Educational Codeforces Round 53 (Rated for Div. 2)D(模拟)
程序员文章站
2024-03-06 21:38:56
...
D. Berland Fair
题解:考虑到每次都会有重复过程。因此我们首先可以算出一轮下来的花费和收获,然后算出这一次会循环多少轮,再给对一轮的花费取模就可以算出剩下的钱。以此反复,继续算下一次的花费和收获。
代码
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int N = 200100;
LL T;
int a[N], n;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
#endif
scanf("%d %lld",&n,&T);
LL Min = 1e18;
for(int i = 0; i < n; ++i){
scanf("%d",&a[i]);
Min = min(Min,1LL*a[i]);
}
LL ans = 0;
for( ; Min <= T; ){
LL cnt = 0, ret = 0;
for(int i = 0; i < n; ++i){
if(a[i] <= T)
T -= a[i], ret += a[i], cnt++;
}
ans += T / ret * cnt + cnt;
T %= ret;
}
printf("%lld\n",ans);
return 0;
}
推荐阅读
-
Educational Codeforces Round 42 (Rated for Div. 2) E. Byteland, Berland and Disputed Cities
-
Educational Codeforces Round 53 (Rated for Div. 2)D(模拟)
-
Educational Codeforces Round 53 (Rated for Div. 2) D - Berland Fair
-
Educational Codeforces Round 53 (Rated for Div. 2)
-
Educational Codeforces Round 53 (Rated for Div. 2)D. Berland Fair
-
【 Educational Codeforces Round 53 (Rated for Div. 2) D. Berland Fair】思维题
-
Codeforces Round #252 (Div. 2)-C,D_html/css_WEB-ITnose
-
Codeforces Round #256 (Div. 2) D. Multiplication Table_html/css_WEB-ITnose
-
Educational Codeforces Round 81 (Rated for Div. 2) - D. Same GCDs - 扩欧+欧拉函数
-
Codeforces Round #220 (Div. 2) D 树状数组 && 二分_html/css_WEB-ITnose