WA in #1,80求调!!
查看原帖
WA in #1,80求调!!
1081217
PLA___NAVY楼主2024/6/27 09:24

请求各位大佬看一看,问题在哪儿??改出必加关注!!

急需代码


(周末愉快)(题目链接)以下是代码:

#include<bits/stdc++.h>
using namespace std;
struct gold{
	int weight;
	int value;
	int temp;
}g[105];
bool cmp(gold x,gold y){
	double a,b;
	a=(x.value*1.0)/(x.weight*1.0);
	b=(y.value*1.0)/(y.weight*1.0);
	return a>=b;
}
int main(){
	int n,t;
	double ans;
	cin>>n>>t;
	for(int i=0;i<n;i++){
		cin>>g[i].weight>>g[i].value;
		g[i].temp=g[i].weight;
	}
	sort(g,g+n,cmp);
	int x=0;
	while(t!=0){
		t--;
		ans+=(g[x].value*1.0)/(g[x].weight*1.0);
		g[x].temp--;
		if(g[x].temp==0)x++;
	}
	printf("%.2f",ans);
	return 0;
}

2024/6/27 09:24
加载中...