poj 3040 这种贪心水题 居然花了我这么久 。。。
2014-03-04 12:28
399 查看
#include<stdio.h> #include<string.h> #include <iostream> #include <algorithm> #include <utility> using namespace std; #define INF 1000000000 pair<int, int> a[30]; /* int mindate(int q,int w){ if(q<w) return q; else return w; }*/ int main(){ int n,c; int use[30]; scanf("%d%d",&n,&c); int i,j,k; int ans,mi; for(i=0;i<n;i++){ scanf("%d%d",&a[i].first,&a[i].second); } sort(a,a+n); ans=0; for(i=n-1;i>=0;i--){ if(a[i].first>=c){ ans+=a[i].second; a[i].second=0; } } while(true){ int money=c; int yes=0; memset(use,0,sizeof(use)); for(j=n-1;j>=0;j--){ if(a[j].second>0){ int date=min(a[j].second,money/a[j].first); use[j]=date; money-=(date*a[j].first); if(money<=0){ yes=1; break; } } } if(money > 0) { for(int i = 0; i < n; i++) if(a[i].second > use[i]) { while(use[i] < a[i].second) { money -= a[i].first; use[i]++; if(money <= 0) { yes = 1; break; } } if(money <= 0) break; } } if(!yes) break; int mi = INF; for(int i = n - 1; i >= 0; i--) if(use[i]) mi = min(mi, a[i].second / use[i]); ans += mi; for(int i = n - 1; i >= 0; i--) if(use[i]) a[i].second-= mi * use[i]; } printf("%d\n",ans); return 0; }
相关文章推荐
- poj Yogurt factory (贪心水题)
- POJ 3040- Allowance(贪心)
- poj3040 贪心
- 两道中等贪心题,poj 3040, poj 3190
- 【POJ】3040 - Allowance(贪心)
- poj 3040 深入理解贪心思想
- [POJ 3040] Allowance (贪心)
- (Relax 贪心1.4)POJ 2325 Persistent Numbers(使用贪心策略解决这么一个问题: 给定一个数n,求一个最小的数m,使得m的各位的乘积==n)
- poj 3040 Allowance 贪心
- POJ 3040 - Allowance(贪心)
- poj 1328 贪心 水题
- poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)
- *Allowance(POJ 3040, 贪心)
- POJ 3040 Allowance 贪心
- POJ 3040 Allowance 贪心
- poj 2034(dfs。。。居然别一个水题卡住了)
- POJ-----3040贪心
- Allowance (poj 3040 贪心)
- POJ 3040 贪心
- 【POJ】3040 - Allowance 贪心