Educational Codeforces Round 48 (Rated for Div. 2)---- A ---- Death Note

        题意有点难读懂,不过看下note就明白了,那么就对每一天记录一下写完那么多还剩下多少,除法算出个数,模数算出余数,每一天都记录一下答案即可。

代码如下


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6 + 10;
int a[maxn],ans[maxn];
int main(){
    int n,m,k = 0;
    cin >> n >> m;
    int left = m;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        if (a[i] < left){
            left -= a[i];
            ans[k++] = 0;
            continue;
        }else{
            a[i] -= left;
            ans[k++] = a[i]/m + 1;
            left = m - a[i] % m;
            if (left == 0) left = m;
          //  cout << left << ' ' << ans[k-1] << endl;
          //  if (i == n-1 && left == 0) an s[k-1]--;
        }
    }
    for (int i=0; i<k; i++) {
        cout << ans[i] << ' ';
    }
    cout << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/CCCCTong/article/details/81590659