标签:测试 scan logs 利用 分割 const com osi 小数
1797:金银岛
2 50 4 10 100 50 30 7 34 87 100 10000 5 1 43 43 323 35 45 43 54 87 43
171.93 508.00
#include<iostream> #include<iomanip> #include<algorithm> #include<cmath> #include<cstdio> #include<cstdlib> #include<queue> #include<stack> #include<cstring> using namespace std; int k; int shubao,zhonglei; struct haosicheng{ int zongjiazhi,zongzhiliang; double danjia; }item[500]; double mycomp(const haosicheng &a,const haosicheng &b) { return a.danjia>b.danjia; } void init() { int k; scanf("%d",&k); for(int i=1;i<=k;i++) { scanf("%d",&shubao); scanf("%d",&zhonglei); for(int j=1;j<=zhonglei;j++) { scanf("%d%d",&item[j].zongzhiliang,&item[j].zongjiazhi); item[j].danjia=(double)item[j].zongjiazhi/(double)item[j].zongzhiliang; } sort(item+1,item+(zhonglei+1),mycomp); double worth=0; for(int i=1;i<=zhonglei;i++) { if(shubao>=item[i].zongzhiliang) { worth=worth+item[i].danjia*item[i].zongzhiliang; shubao=shubao-item[i].zongzhiliang; } else { worth=worth+item[i].danjia*shubao; shubao=shubao-shubao; } } printf("%.2lf\n", worth); } } int main() { init(); return 0; }
标签:测试 scan logs 利用 分割 const com osi 小数
原文地址:http://www.cnblogs.com/suibingchen/p/6848324.html