求助!85分不知道哪里有问题(这是菜鸟我现场写的TAT
查看原帖
求助!85分不知道哪里有问题(这是菜鸟我现场写的TAT
927823
fw_OIer楼主2024/4/1 11:19
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
int n,d,v[10000001]/*i站到i+1站的距离*/,a[10000001],gl,yuan,wei=1;
double you;
int main(){
	cin >> n >> d;
	for(int i=1;i < n;i++){
		cin >> v[i];
	}
	for(int i=1;i <= n;i++){
		cin >> a[i];
	}
	for(int i=1;i < n;i++){
		gl += v[i];
//		cout << "现在在" << wei << "-" << a[wei] << "站" << endl; 
//		cout << "要走" << gl << "公里-------" << endl; 
		int shen;
		if(a[i+1] <= a[wei] || i+1 == n){
//			cout << "去" << i+1 << "-" << a[i+1] << "站--------" << endl; 
			if(int(gl/d)*d < gl) shen = int(gl/d)+1;
			else shen = int(gl/d);
//			cout << "要加" << shen << "升油" << "---" << endl; 
			double tt = shen+you;
			if(d*tt >= gl && d*tt-gl >= d){
				shen--;
			}
			you += shen;
			yuan += shen*a[wei];
//			cout << "总共花了" << yuan << "元" << endl; 
			wei = i+1;
			i = wei-1;
			you -= gl/(d*1.0);
			gl = 0;
//			cout << "还有" << you << "油" << endl; 
		}
	}
	cout << yuan;
	return 0;
}
2024/4/1 11:19
加载中...