杂题专项:UVa 10670
来源:互联网 发布:正道集团 知乎 编辑:程序博客网 时间:2024/05/21 06:01
一道贪心,即在花费小于减的情况下尽量除。注意最后剩下exactly m,不能小于m。另外因为输出的限制,所以建立一个结构体并用algorithm里的sort可以方便的满足要求。
#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;#define M 110struct agency{ char name[20]; int cost; bool operator<(const agency& tmp) const { return cost<tmp.cost||cost==tmp.cost&&strcmp(name,tmp.name)<0; }} a[M];int n,m,l;int main(){ freopen("in.txt","r",stdin); int T; int kase=1; cin>>T; while(T--) { cin>>n>>m>>l; int A,B; for(int i=0;i<l;i++) { char c; int len=0; while(c=getchar()) { if(c==':') break; if(!isupper(c)) continue; a[i].name[len++]=c; } a[i].name[len]='\0'; scanf("%d,%d",&A,&B); int s=n; a[i].cost=0; while(s/2>=m&&(s-s/2)*A>=B) { a[i].cost+=B; s/=2; } a[i].cost+=(s-m)*A; } sort(a,a+l); cout<<"Case "<<kase++<<endl; for(int i=0;i<l;i++) { cout<<a[i].name<<" "<<a[i].cost<<endl; } } return 0;}
- 杂题专项:UVa 10670
- 杂题专项:UVa 10382
- 杂题专项:UVa 10012
- 杂题专项:UVa 818
- 杂题专项:UVa 11627
- 字符串专项:UVa 12012
- 搜索专项:UVa 10318
- 字符串专项:UVa 10298
- 字符串专项:UVa 11475
- 字符串专项:UVa 11855
- 杂题专项:LA 3602
- 杂题专项:LA 5842
- 数学专项counting:UVa 11038
- 数学专项counting:UVa 10883
- 计算几何专项:UVa 11437
- 计算几何专项:UVa 11646
- 计算几何专项:UVa 11817
- 计算几何专项:UVa 11524
- 收藏的网页-c/c++
- 预判未来、在对的时间做对的事情、顺势而为
- xfire spring3兼容问题
- Html表格常用技巧
- 彻底卸载91 手机助手(Iphone)珍惜生命,请远离91!
- 杂题专项:UVa 10670
- Windows OpenGL(1) Hello
- AWR
- Collection 和 Collections的区别。
- Hadoop环境搭建——伪分布式环境搭建
- openssl签名验证、信封加密解密、产生随机数、md5摘要
- 简单的置换算法
- 省赛热身赛之Light Bulb
- Linux修改文件及文件夹权限