[POJ 3040] Allowance (贪心)
来源:互联网 发布:ubuntu开机黑屏 编辑:程序博客网 时间:2024/06/16 07:36
POJ - 3040
FJ手中有若干面值的货币,小面值的货币能被大面值的整除
每周他要给奶牛发不少于 C的工资,问最多能发几周
首先大于 C的面值都先发掉
然后优先发剩下的大面额的货币,当超过时
将最后一个大面额的用尽可能小的货币代替
#pragma comment(linker, "/STACK:102400000,102400000")#include <cstdio>#include <iostream>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <map>#include <set>#include <queue>using namespace std;typedef pair<int,int> Pii;typedef long long LL;typedef unsigned long long ULL;typedef double DBL;typedef long double LDBL;#define MST(a,b) memset(a,b,sizeof(a))#define CLR(a) MST(a,0)#define Sqr(a) (a*a)const int INF=0x3f3f3f3f;struct data{ int v,b; bool operator < (const data &y) const {return v < y.v;}} inpt[30];int N,C;int have[30];inline void pause(){fflush(stdin); getchar();}int main(){ #ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout); #endif while(~scanf("%d%d", &N, &C)) { for(int i=0; i<N; i++) scanf("%d%d", &inpt[i].v, &inpt[i].b); sort(inpt, inpt+N); LL ans=0; while(N && inpt[N-1].v >= C) ans += inpt[--N].b; while(1) { for(int i=0; i<N; i++) have[i]=inpt[i].b; int left=C; for(int i=N-1; i>=0; i--) { int cnt = left/inpt[i].v; if(have[i] < cnt) continue; have[i] -= cnt; left -= cnt*inpt[i].v; } for(int i=0; i<N; i++) { int cnt = left/inpt[i].v; if(left%inpt[i].v) cnt++; if(have[i] < cnt) cnt = have[i]; have[i] -= cnt; left -= cnt*inpt[i].v; if(left <= 0) break; } if(left > 0) break; int tims=INF; for(int i=0; i<N; i++) if(have[i] < inpt[i].b) tims = min(tims, inpt[i].b/(inpt[i].b - have[i])); ans+=tims; for(int i=0; i<N; i++) if(have[i] < inpt[i].b) inpt[i].b -= (inpt[i].b - have[i])*tims; } printf("%lld\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 贪心
- haartraining训练生成xml过程
- HDU 1171.Big Event in HDU【01背包】【5月26】
- mina第一篇:基本demo实现
- android Gson解析
- linux 自行安装lanmp
- [POJ 3040] Allowance (贪心)
- Cocos2dx 3.x移植Android及打包
- Xcode 7 缺少 *.dylib库的解决方法
- 最佳A*算法【转】
- 【转载】dubbo学习
- typeof 预算符
- BZOJ3125: CITY
- Linux基础篇之文本、数据流处理命令
- C++设计模式浅识原型模式