求优化
查看原帖
求优化
559847
Ferm_Tawn楼主2022/9/4 17:55

70分

#include<bits/stdc++.h>
#define int long long
using namespace std;
double r;
double last = 0;
int a[100005];
int n , x , p , q , pos = 1;
signed main(){
	cin >> n >> x >> p >> q;
	r = ((p * 1.0) / (q * 1.0)) * (x * 1.0);
	for(int i = 1 ; i <= n ; i++) cin >> a[i];
	for(int t = 1 ; ; t++){
		double work = (x * 1.0) - (r - last);
		double coun = 0;
		for(int i = pos ; ; i++){
			if(pos > n){
				cout << t;
				return 0;
			}
			if(work - a[i] >= 0 && coun + a[i] < x){
				pos++;
				work -= a[i];
				coun += a[i];
			}
			else break;
		}
		last = work;
	}
	return 0;
}
2022/9/4 17:55
加载中...