codeforces1073d

  和B题一样,也是模拟题,不过这道题我们可以优雅地模拟。

  有一点得说明,那就是写模拟题,题意的理解非常重要,而本题就像绕圈割韭菜,每割一棵韭菜要消耗一定的能量,只要自己的

后备储藏能源足够,就可以割下它,否则就割下一棵(如果下一棵可以割的话,不然又得割下一棵)。粮草未动,代码先行~

c++代码如下:

#include<bits/stdc++.h>
using namespace std;
const int M = 2e5 + 5;
using ll = long long;

int a[M];
int main()
{
    int n;
    ll T;
    scanf("%d %lld", &n, &T);
    ll ans = 0;
    for (int i=0; i<n; i++){
        scanf("%d", &a[i]);
    }

    while(true){
        ll cnt = 0, sum = 0;
        for(int i=0; i<n; i++){
            if(a[i] <= T){
                sum += a[i];
                T -= a[i];
                cnt++;
            }
        }
        if(!cnt){
            break;
        }
        ans += cnt;
        ans += cnt * (T / sum);
        T %= sum;//求余的特点,商不一定为1,所以有了上一步
    }
    printf("%lld\n", ans);
}

  

猜你喜欢

转载自www.cnblogs.com/mifankai/p/9860451.html