文章

81

粉丝

0

获赞

282

访问

11.0k

头像
奇怪的餐厅 题解:
P1670 中南大学机试题
发布于2025年3月19日 12:39
阅读数 85

#include<bits/stdc++.h>
using namespace std;
struct people{
	double discount;
	double t;
};
bool cmp(people a,people b){
	if(a.discount != b.discount){
		return a.discount < b.discount;
	}
	else{ return  a.t > b.t ;}
}
int main(){
	int n,total,ans,tmp;
	while(cin>>n>>total){
		people p[100];
		tmp = total;
		ans = 0;
		for(int i=0;i<n;i++){
			cin>>p[i].discount>>p[i].t;
		}
		sort(p,p+n,cmp);
		for(int i=0;i<n;i++){
			double t=p[i].discount*p[i].t;
			if(tmp < p[i].t) {
				ans+= tmp*p[i].discount;
				tmp = 0;
			
				break;
			}
			ans+=t;
			tmp-=p[i].t;
		}
		if(tmp!=0){
			ans+=tmp;
		}
		cout<<ans<<endl;
	}
	return 0;

}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发