HDU2333(二分答案)
来源:互联网 发布:unity3d人物模型 编辑:程序博客网 时间:2024/06/03 15:57
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.
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 one integer: the maximal possible quality.
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
9
#include <iostream>#include <map>#include <cstdio>#include <string.h>#define INF 0x3f3f3f3fusing namespace std;map<string,int>mp;const int AX = 1e3+666;int n,m;int id;char tmp[100];char tmp2[100];struct Node{int type;int quality;int price;}s[AX];bool judge(int x){int cnt = 0;int minprice[AX];int budget = 0;memset(minprice,INF,sizeof(minprice));for(int i=1;i<=n;i++){if(s[i].quality < x) continue;if(minprice[s[i].type] == INF){cnt++;minprice[s[i].type] = s[i].price;budget += s[i].price;}else if(minprice[s[i].type] > s[i].price){budget = budget - minprice[s[i].type] + s[i].price;minprice[s[i].type] = s[i].price;}}return (cnt == id - 1 && budget <= m);}int main(){int T;scanf("%d",&T);while(T--){int maxquality = 0;id = 1;mp.clear();scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%s%s",tmp,tmp2);if(!mp[tmp]){mp[tmp] = id++;s[i].type = mp[tmp];}else{s[i].type = mp[tmp];}scanf("%d%d",&s[i].price,&s[i].quality);maxquality = max(maxquality,s[i].quality);}int l = 0,r = maxquality;//for(int i=1;i<=n;i++) cout<<s[i].type<<endl;while(l < r){int mid=l+(r-l+1)/2;if(judge(mid)) l = mid;else r = mid - 1;}printf("%d\n",l);}return 0;}
阅读全文
0 0
- HDU2333(二分答案)
- HDU2333 Assemble(二分)
- HDU2333 Assemble 二分
- 华哥倒酒(二分答案)
- number (二分答案)
- 二分答案(by jie)
- POJ 3122(二分答案)
- Space Golf (二分答案)
- POJ3104 Drying(二分答案)
- test 排序(二分答案)
- Voltage Keepsake(二分答案)
- 装果子(二分答案)
- POJ-3273(二分答案)
- 健身计划(二分答案)
- 二分答案
- 二分答案
- 二分答案
- 二分答案
- Android GUI FramebufferNativeWindow ANativeWindow
- Win32 SOCKET之UDP
- 目前为止最全的微信小程序项目实例
- 理解RESTful架构
- OpenGL ES应用开发实践指南(android 卷)笔记 第一章
- HDU2333(二分答案)
- C++ 虚函数表解析
- Trailing Zeroes
- tensorflow安装记录
- java基础习题50道(六)
- android中的后退键——onBackPressed()的使用
- Python_format()格式化函数
- jni 内存溢出
- android activityInfo