POJ3497 Assemble(二分)
来源:互联网 发布:BFGS算法程序 编辑:程序博客网 时间:2024/06/16 10:35
Link:http://poj.org/problem?id=3497
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 ≤
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.
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
AC code:
#include<iostream>#include<stdio.h>#include<algorithm>#include<math.h>#include<string.h>#include<map>#include<set>#include<vector>#define LL long long#define INF 0xfffffff#define PI acos(-1)#define EPS 1e-6using namespace std;struct node{int price;int quality;};int n,b,num;map<string,int>m;vector<node>v[1010];bool buy(int m,int b){int cnt=0,i,j,mon,minp;mon=b;for(i=1;i<=num;i++){minp=INF;for(j=0;j<v[i].size();j++){if(v[i][j].quality>=m && v[i][j].price<=minp){minp=v[i][j].price;}}if(minp==INF)return false;else{mon-=minp;if(mon<0)return false;}}return true;}int Bsearch(int l,int h){int m,res;res=0;while(l<=h){m=(l+h)>>1;if(buy(m,b)){res=m;l=m+1;}else{h=m-1;}}return res;}int main(){//freopen("in.txt","r",stdin);int t,i,p,q,low,high,ans;char typ[111],nam[111];scanf("%d",&t);while(t--){scanf("%d%d",&n,&b);m.clear();num=0;low=0;high=0;for(i=0;i<n;i++){scanf("%s%s%d%d",&typ,&nam,&p,&q);high=max(high,q);if(m.find(typ)==m.end()){m[typ]=++num;v[m[typ]].clear();}node data;data.price=p;data.quality=q;v[m[typ]].push_back(data);}ans=Bsearch(low,high);printf("%d\n",ans);}return 0;}
- POJ3497 Assemble(二分)
- POJ3497 Assemble 二分+贪心
- POJ3497 UVA12124 Assemble(二分 + 贪心)
- 【二分答案】 【POJ3497】 【Northwestern Europe 2007】 Assemble 组装电脑
- ZOJ3090 POJ3497 HDU2333 Assemble
- LA3971&&HDU2333&&POJ3497-Assemble
- Assemble HDU2333 || uva12124 || poj3497 || zoj3090
- HDU2333 Assemble(二分)
- UVA 12124 - Assemble(二分)
- LA3971-Assemble(贪心+二分)
- uvalive 3971 - Assemble(二分搜索 + 贪心)
- Uva 12124 Assemble 解题报告(二分)
- UVA 12124 Assemble(贪心 二分)
- uvalive 3971 - Assemble(二分搜索 + 贪心)
- UVALive 3971-Assemble- 最小值最大化(二分)
- UVALive 3971 Assemble(二分 + 贪心)
- UVA 12124 Assemble (二分 + 字典树)
- HOJ 2608 Assemble(二分)
- 即时执行:一个由运行定义的命令式 TensorFlow 接口
- Quartz学习(3)
- String字符串对象
- JAVA中的反射机制
- C语言模型:内存四区模型和函数调用模型
- POJ3497 Assemble(二分)
- 【整理】SIMD、MMX、SSE、AVX、3D Now!、neon
- 【Scikit-Learn 中文文档】支持向量机
- C# Emgu 人脸识别(已测试)
- 谷歌浏览器记住密码后input输入框背景变为黄色
- DevOps工具集最佳实践分享
- 字符流与字节流详解
- HBase学习笔记
- LoadRunner工具的菜单详解