解题报告:HDU_2333 Assemble 二分
来源:互联网 发布:人工智能电影精彩影评 编辑:程序博客网 时间:2024/06/05 02:31
Assemble
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 654 Accepted Submission(s): 237
Problem 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.
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 ≤ 1 000, the number of available components and 1 ≤ b ≤ 1 000 000 000, 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 ≤ 1 000 000) which represents the price of the component and quality is an integer (0 ≤ quality ≤ 1 000 000 000) 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.
One line with two integers: 1 ≤ n ≤ 1 000, the number of available components and 1 ≤ b ≤ 1 000 000 000, 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 ≤ 1 000 000) which represents the price of the component and quality is an integer (0 ≤ quality ≤ 1 000 000 000) 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.
Output
Per testcase:
One line with one integer: the maximal possible quality.
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
Source
Northwestern Europe 2007
Recommend
zty
#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<queue>#include<map>#include<iostream>using namespace std;map<string,int>M;struct obj{ int pr; int k; obj(){} obj(int a,int b){ pr = a;k =b; }}A[1005][1005];int cnt[1005],m;int n,sum,price,k;inline bool cmp(const obj& a,const obj& b){ if(a.k==b.k){ return a.pr<b.pr; }return a.k>b.k;}bool judge(int x){ int res = sum; for(int i=1;i<=m;i++){//printf("i=%d\n",i); int id = -1 , p = res; for(int j=0;j<cnt[i];j++){ if(A[i][j].k>=x){ if(A[i][j].pr<=p){ id = j; p = A[i][j].pr; } } }if(id==-1){ return false ; }else { res -= p; } } return res>=0;}inline void print(){ for(int i=1;i<=m;i++){printf("-------i=%d\n",i); for(int j=0;j<cnt[i];j++){ printf("%d %d \n",A[i][j].pr,A[i][j].k); } }}int main(){ int T; scanf("%d",&T);ios::sync_with_stdio(0); while(T--){ M.clear(); memset(A,0,sizeof(A)); memset(cnt,0,sizeof(cnt));m = 0; string str,tmp;int s = 0 , e = 0; n=0,sum=0,price=0,k=0; cin>>n>>sum; while(n--){ cin>>str>>tmp>>price>>k; e = max(k,e); if(!M.count(str)){ M[str]=++m; }int t = M[str]; A[t][cnt[t]++]=obj(price,k); }for(int i=1;i<=m;i++){ sort(A[i],A[i]+cnt[i],cmp); }//print(); int mid; while(s<=e){ mid = (s+e)/2; if(mid==s){ break; }//printf("mid=%d\n",mid); if(judge(mid)){ s = mid; }else { e = mid - 1; } }if(judge(s+1)){ s++; } printf("%d\n",s); } return 0;}
0 0
- 解题报告:HDU_2333 Assemble 二分
- LA_3635/HDU_2333 Assemble (二分)
- Uva 12124 Assemble 解题报告(二分)
- UVA 12124 - Assemble 解题报告
- 【Jason's_ACM_解题报告】Assemble
- 【二分】软件下载解题报告
- [bzoj4025]二分图 解题报告
- POJ3497 Assemble 二分+贪心
- HOJ 2608 Assemble(二分)
- LA 3971 Assemble / 二分
- hdu 2333 Assemble 二分
- 12124Assemble【二分】
- Hdoj 2333 Assemble 【二分】
- hdu 2333 Assemble 二分
- HDU2333 Assemble 二分
- UVA 12124 Assemble(二分)
- HDU2333 Assemble(二分)
- POJ3497 Assemble(二分)
- python break,pass,continue 循环语句
- ANR log分析
- 图片自动缩放,前台读富文本编辑器里图片用的
- PHP 漏洞与代码审计
- Qt之qInstallMessageHandler(重定向至文件)
- 解题报告:HDU_2333 Assemble 二分
- 使用MyEclipse构建MAVEN项目(非WEB项目)
- Test
- winpcap环境搭建Visual Studio 2010
- 阿里面经之解答 by cmershen(4)——线程池
- android Handler 用法
- angularjs踩过的那些坑
- hello world(android volley)
- usage of map