Assemble
来源:互联网 发布:java作业题 编辑:程序博客网 时间:2024/04/29 09:11
Description
Recently your team noticed that the computer you use to practice for programming contests is not good enough anymore. Therefore, you decide to buy a new computer.
To make the ideal computer for your needs, you decide to buy separate components and assemble the computer yourself. You need to buy exactly one of each type of component.
The problem is which components to buy. As you all know, the quality of a computer is equal to the quality of its weakest component. Therefore, you want to maximize the quality of the component with the lowest quality, while not exceeding your budget.
Input
On the first line one positive number: the number of testcases, at most 100. After that per testcase:
- One line with two integers: 1 ≤ n ≤ 1000, the number of available components and 1 ≤ b ≤ 1000000000, your budget.
- n lines in the following format: ``type name price quality'', where type is a string with the type of the component, name is a string with the unique name of the component, price is an integer (0 ≤ price < 1000000) which represents the price of the component and quality is an integer (0 ≤ quality ≤ 1000000000) which represents the quality of the component (higher is better). The strings contain only letters, digits and underscores and have a maximal length of 20 characters.
It will always possible to construct a computer with your budget.
Output
Per testcase:
- One line with one integer: the maximal possible quality.
Sample Input
118 800processor 3500_MHz 66 5processor 4200_MHz 103 7processor 5000_MHz 156 9processor 6000_MHz 219 12memory 1_GB 35 3memory 2_GB 88 6memory 4_GB 170 12mainbord all_onboard 52 10harddisk 250_GB 54 10harddisk 500_FB 99 12casing midi 36 10monitor 17_inch 157 5monitor 19_inch 175 7monitor 20_inch 210 9monitor 22_inch 293 12mouse cordless_optical 18 12mouse microsoft 30 9keyboard office 4 10
Sample Output
9
#include<iostream>#include<cstdio>#include<vector>#include<map>using namespace std;int ans,m,b;map<string,int> Type;int ID(string s){if(!Type.count(s)) Type[s]=ans++;return Type[s];}struct component{int price;int quality;};vector<component> comp[1005]; bool ok(int mq){int sum=0;for(int i=0;i<ans;i++){int cheap=b;for(int j=0;j<(comp[i].size());j++){if(comp[i][j].quality>=mq) cheap=min(comp[i][j].price,cheap);}if(cheap==b) return false;sum+=cheap;}if(sum>b) return false;else return true;}int main(){int T;cin>>T;while(T--){int n,maxq=0;ans=0;scanf("%d%d",&n,&b);Type.clear(); //千万不要忘记!for(int i=0;i<n;i++)comp[i].clear();for(int i=0;i<n;i++){char type[22],name[22];int p,q;scanf("%s%s%d%d",type,name,&p,&q);maxq=max(maxq,q);comp[ID(type)].push_back((component){p,q});}int l=0,r=maxq;while(l<r){m=l+(r-l+1)/2;if(ok(m)) l=m;else r=m-1;}printf("%d\n",l);}return 0;}(写完程序之后,我测试了好几次都未通过,最后发现是未将comp和Type内的数据清除)
- assemble
- Assemble
- Assemble
- 12124 - Assemble
- LA3971 - Assemble
- UVa12124 - Assemble
- uva12124-Assemble
- LA3971 Assemble
- LA3971 Assemble
- uva12124 Assemble
- WOJ1303-Assemble
- 【UVA12124】Assemble
- arm assemble and gnu assemble
- Intel Assemble Instruction Set
- Intel Assemble Instruction Set
- POJ3497 Assemble 二分+贪心
- hoj 2608 Assemble
- ZOJ3090 POJ3497 HDU2333 Assemble
- hdu1054 树形dp
- stm32 GPIO口初认识
- 设有两个栈S1和S2都采用顺序栈的方式存储,并且共享一个存储区
- django 模板使用css js
- java经典五十道题之1兔子问题
- Assemble
- zTree -- jQuery 树插件
- URAL 1572. Yekaterinozavodsk Great Well(数学啊)
- 服务器结构探讨
- Tomcat 项目部署以及数据源的配置
- Android进程性能监控工具Honeybadger实现
- caffe源码解析之添加新的Layer(maxout)
- ubuntu14.04安装pt-2012.12 / icc-2013.03 / spyglass-4.4.0过程记录
- codeforces 500C New Year Book Reading (贪心,很好的思维题)