神奇的错误
查看原帖
神奇的错误
218180
lighthouse楼主2021/7/8 15:29

样例已过,第一个点WA……

#include <bits/stdc++.h>

using namespace std;

struct gold{
	int m, v;
}a[110];

bool cmp(gold x, gold y){
	return x.v * y.m > y.v * x.m;
}

int main(){
	int n, t, c;
	cin >> n >> t;
	double ans = 0;
	c = t;
	for(int i = 0;i < n;i++){
		cin >> a[i].m >> a[i].v;
	}
	sort(a, a + n, cmp);
	int k;
	for(int i = 0;i < n;i++){
		if(a[i].m > c){
			k = i;
			break;
		}
		c -= a[i].m;
		ans += a[i].v;
	}
	if(k < n){
		ans += 1.0 * c / a[k].m * a[k].v;
	}
	cout << fixed << setprecision(2) << ans;
	return 0;
}

然而把cout << fixed << setprecision(2) << ans;改成printf("%.2lf", ans);后第一个点从WA变成了RE…………
求大佬指教

2021/7/8 15:29
加载中...