HDU1009 解题报告
2017-07-24 20:23
183 查看
FatMouse' Trade
[b]Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 79626 Accepted Submission(s): 27496
[/b]
[align=left]Problem Description[/align]
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.
The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of
cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.
[align=left]Input[/align]
The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then
b0d9
N lines follow, each contains two non-negative integers J[i] and F[i] respectively.
The last test case is followed by two -1's. All integers are not greater than 1000.
[align=left]Output[/align]
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.
[align=left]Sample Input[/align]
5 3
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
[align=left]Sample Output[/align]
13.333
31.500
[align=left]Author[/align]
CHEN, Yue
[align=left]Source[/align]
ZJCPC2004
[align=left]Recommend[/align]
JGShining | We have carefully selected several similar problems for you: 1008 1050 1005 1051 1004
做法:贪心
将输入的每一对数据按照(cat food)/javabean从大到小排列,从多的开始取,一直到猫粮用完
#include<iostream> #include<algorithm> #include<cstdio> using namespace std; struct Trade{ double j; //Javabean double f; //cat food double jf; //每一单位cat food可以得到的Javabean }; const double INF=2e9; const int maxn=1000+10; int N; double M; //N行,M猫粮数目 Trade trade[maxn]; void solve(); bool cmp(const Trade &t1,const Trade &t2); int main() { while(cin>>M>>N) { if(N==-1&&M==-1) break; for(int i=0;i<N;i++) { scanf("%lf%lf",&trade[i].j,&trade[i].f); if(trade[i].f==0) trade[i].jf=INF; else trade[i].jf=trade[i].j/trade[i].f; } solve(); } return 0; } bool cmp(const Trade &t1,const Trade &t2) { return t1.jf>t2.jf; } void solve() { sort(trade,trade+N,cmp); double ans=0; for(int i=0;i<N;i++) { Trade t=trade[i]; if(M>t.f) { ans+=t.j; M-=t.f; } else { ans+=(M/t.f)*t.j; break; } } printf("%.3f\n",ans); }
相关文章推荐
- HDU解题报告——1009
- HDU 1009 FatMouse' Trade 解题报告
- HDU 4869 Turn the pokers (2014多校联合训练第一场1009) 解题报告(维护区间 + 组合数)
- HDU 4869 Turn the pokers (2014多校联合训练第一场1009) 解题报告(维护区间 + 组合数)
- 2012 Multi-University Training Contest 9 1009解题报告 HDU 4388
- Hdu 1009 FatMouse' Trade解题报告
- hdu_2031_进制转换_解题报告
- hdu 2049 不容易系列之(4)——考新郎 解题报告
- HDU 1111 Secret Code DFS 解题报告
- HDU - 1010 Tempter of the Bone 深搜模板题(DFS)解题报告
- hdu2795 解题报告 Billboard
- 解题报告:HDU 5763
- Hdu 1005 解题报告
- HDU 1281解题报告
- hdu 2586 How far away? LCA 解题报告
- hdu 2037 今年暑假不AC 解题报告
- HDU 4196解题报告
- BestCoder15 1002.Instruction(hdu 5083) 解题报告
- HDU 4252 A Famous City 解题报告
- 解题报告:HDU_2333 Assemble 二分