Codeforces 1190A Tokitsukaze and Discard Items

题目链接:http://codeforces.com/problemset/problem/1190/A

Codeforces 1190A Tokitsukaze and Discard Items

Codeforces 1190A Tokitsukaze and Discard Items


思路:模拟模拟到吐 呜呜...看代码吧。

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
long long a[maxn];
long long n,k,m;
int main()
{
    cin >> n >> m >> k;
    long long ans = 0;
    long long s = 0;//延迟量
    long long kk = k;// 基础 k 值
    long long sum = 0;//延迟总量
    for(int i = 0;i < m;i++)
    {
        cin >> a[i];
    }
    for(int i = 0;i < m;i++)
    {
        if(a[i] <= k + sum) s++;//如果这一页有特殊项目 则标记量增加
        else
        {
            if(s > 0)//如果标记量增加过
            {
                sum += s;
                i--;//回溯
                ans ++,s = 0;
                //cout << ans << " " << sum << " " << k << endl;
            }
            else if((a[i]-k - sum)/kk > 10) k = (a[i]-kk)/kk*kk,i--;//防止 TLE ,但相差页数过大 则直接跳到那页。
            else k+=kk,i--;//一页一页翻
        }
    }
    if(s > 0) ans++;
    cout << ans;
    return 0;
}