首页 > 其他 > 详细

[HAOI2013] 花卉节

时间:2018-04-15 18:37:32      阅读:146      评论:0      收藏:0      [点我收藏+]

  贪心,尽量捡便宜的买,反正是糊弄更多的老百姓开心。

 

// q.c

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef unsigned long long ULL;
const int M=100000+10;
struct Flower { 
	ULL cost,lover;
	bool operator < (const Flower &A) const {
		if(cost!=A.cost) return cost<A.cost;
		else return lover>A.lover;
	}
}flower[M];
int n; ULL b,ans;
int main() {
	freopen("haoi13_t2.in","r",stdin);
	freopen("haoi13_t2.out","w",stdout);
	cin>>n>>b;
	for(int i=1;i<=n;i++) cin>>flower[i].cost>>flower[i].lover;
	sort(flower+1,flower+n+1);
	for(int i=1;i<=n;i++) {
		ULL cnt=b/flower[i].cost;
		if(!cnt) break;
		if(cnt>flower[i].lover) cnt=flower[i].lover;
		b-=flower[i].cost*cnt;
		ans+=cnt;
	}
	cout<<ans;
	return 0;
}

 

[HAOI2013] 花卉节

原文:https://www.cnblogs.com/qjs12/p/8848689.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!