码迷,mamicode.com
首页 > 其他好文 > 详细

[HAOI2013] 花卉节

时间:2018-04-15 18:48:28      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:break   turn   amp   love   highlight   over   lse   algo   using   

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

 

// 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] 花卉节

标签:break   turn   amp   love   highlight   over   lse   algo   using   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!