1. 程式人生 > >Educational Codeforces Round 53 (Rated for Div. 2)-D.Berland Fair

Educational Codeforces Round 53 (Rated for Div. 2)-D.Berland Fair

思路:直接暴力就能過QAQ,每次模擬掃一遍,得到s個糖果的價格為Sum,然後ans+=(T/Sum)*s,T%=Sum;這樣一直這樣迴圈即可。

我一直以為這樣的時間複雜度是 n*n,所有就沒有交,結果只跑了70ms...,還是太菜,以後不確定的還是要交一遍再說,萬一過了呢— —

Code:

#include<iostream>
using namespace std;
typedef long long LL;

const int MAX_N=2e5+5;
int n;
LL m;
LL a[MAX_N];

int main()
{
	ios::sync_with_stdio(false);
	while(cin>>n>>m){
		for(int i=1;i<=n;++i)
			cin>>a[i];
		LL ans=0,Sum=0,s=0;
		while(1){
			Sum=s=0;
			for(int i=1;i<=n;++i)
				if(Sum+a[i]<=m){
					Sum+=a[i];	++s;
				}
			if(Sum){
				ans+=(m/Sum)*s;
				m%=Sum;
			}else	break;
		}
		cout<<ans<<endl; 
	}
	
	return 0;
}