poj 3040 Allowance (贪心)
来源:互联网 发布:centos怎么下载软件 编辑:程序博客网 时间:2024/05/30 19:34
题意:有各种不同面值xi的硬币ci个,问要给别人发工资(一个星期的工资至少为c)
最多能发给它多少个星期。(小硬币的面值能整除大硬币)
分析:
1、按面值从大到小排序,如果能选大的尽量选大的,只要不超过c就能放多少放多少。
最后再从小的开始找放进去超额的。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct money{ int v,cnt;}coin[25];int need[25];bool cmp(money x,money y){ return x.v>y.v;}int main(){ int n,c,ans; while(scanf("%d%d",&n,&c)!=EOF) { for(int i=1;i<=n;i++) scanf("%d%d",&coin[i].v,&coin[i].cnt); sort(coin+1,coin+n+1,cmp); ans=0; while(1) { memset(need,0,sizeof(need)); int sum=c; for(int i=1;i<=n;i++) { int tmp=sum/coin[i].v; need[i]=min(coin[i].cnt,tmp); sum-=coin[i].v*need[i]; } if(sum>0) { for(int i=n;i>=1;i--) { if(coin[i].cnt && coin[i].v>=sum) { need[i]++; sum=0; break; } } } if(sum>0) break; int s=0x3f3f3f3f; for(int i=1;i<=n;i++) { if(need[i]) s=min(s,coin[i].cnt/need[i]); } ans+=s; for(int i=1;i<=n;i++) { if(need[i]) coin[i].cnt-=need[i]*s; } } printf("%d\n",ans); } return 0;}
0 0
- poj 3040 Allowance (贪心)
- POJ 3040 - Allowance(贪心)
- POJ 3040 Allowance (贪心)
- POJ 3040- Allowance(贪心)
- [POJ 3040] Allowance (贪心)
- 【POJ】3040 - Allowance(贪心)
- *Allowance(POJ 3040, 贪心)
- POJ 3040 Allowance 贪心
- poj 3040 Allowance 贪心
- 贪心-poj-3040-Allowance
- poj 3040 Allowance(贪心)
- poj 3040 Allowance (贪心)
- Allowance - POJ 3040 贪心
- Allowance (poj 3040 贪心)
- poj 3040 Allowance贪心
- POJ 3040 Allowance 贪心
- POJ 3040 Allowance 贪心
- POJ 3040 Allowance 贪心
- 什么是Spark
- 使用Matlab实现图形的刻度,分格线和坐标框
- 浏览器状态码汇总(404,505,200)
- NYOJ 371 机器人II
- 待到山花烂漫,笑在丛中
- poj 3040 Allowance (贪心)
- 黑马程序员-- 六、多线程
- unbutu 安装java教程
- 线程相关函数讲解
- stm32f4xx_it.c: Error: C3065E: type of input file 'DRIVER' unknown 解决办法
- 为什么是“51-android.rules”?
- Sicily 1822. Fight Club
- json换行替换及双引号替换
- Some Matrix manifolds (Lie group, Grassmann manifold and Riemannian manifold) for computer vision