LA 3971 Assemble 组装电脑
2015-07-04 05:08
267 查看
题意:给定电脑的n个配件,每个配件有类型,名字(没用的信息),价格和品质因子。要求每种类型的配件各买一个用于组装电脑,总价格不超过b元。求所有可能的方案中品质因子最差的那个配件的品质因子最大能是多少。
非常的暴力。直接枚举每个配件的品质因子作为品质因子最差的配件,判断该配件的品质因子能否满足要求。能满足则更新最大值。判断方法很简单,对于每种类型的配件选择品质因子不低于当前要判断的数且最便宜的购买。若不超过b元则符合要求否则不符合要求。O(n^2)复杂度。n最大才1000。因此暴力水之。
非常的暴力。直接枚举每个配件的品质因子作为品质因子最差的配件,判断该配件的品质因子能否满足要求。能满足则更新最大值。判断方法很简单,对于每种类型的配件选择品质因子不低于当前要判断的数且最便宜的购买。若不超过b元则符合要求否则不符合要求。O(n^2)复杂度。n最大才1000。因此暴力水之。
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <string> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <map> #include <set> using namespace std; const int MAX = 1005; const int INF = 1000000001; struct Components //组件结构体 { int price; //价格 int quality; //品质因子 }; int n, b; char type[30], name[30]; Components temp; int cnt; map <string, int> id; //对组件种类编号 vector <Components> com[MAX]; //组件 bool judge(int x) { int i, j, sum = 0; for(i = 1; i <= cnt; i++) { int cheapest = INF; for(j = 0; j < com[i].size(); j++) { if(com[i][j].quality >= x) cheapest = min(cheapest, com[i][j].price); } if(cheapest == INF) return false; sum += cheapest; } return sum <= b; } void input() { scanf("%d%d", &n, &b); id.clear(); for(int i = 0; i < MAX; i++) com[i].clear(); cnt = 0; for(int i = 0; i < n; i++) { scanf("%s%s%d%d", type, name, &temp.price, &temp.quality); if(id[type] == 0) id[type] = ++cnt; com[id[type]].push_back(temp); } } void solve() { int ans = 0; for(int i = 1; i <= cnt; i++) { for(int j = 0; j < com[i].size(); j++) { if(judge(com[i][j].quality)) ans = max(ans, com[i][j].quality); } } printf("%d\n", ans); } int main() { int T; scanf("%d", &T); while(T--) { input(); solve(); } return 0; }
相关文章推荐
- 1 用户及用户组、文件夹管理
- MAC 命令
- Decorator Pattern 装饰者模式
- 微信公众号demo
- APP UI设计趋势:为好设计而动
- UVa 10795 A Diffenent Task 新汉诺塔问题
- Observer Pattern 观察者模式
- Adobe Photoshop
- PHP开发之使用CodeIgniter搭建一个简单的项目
- 网络安全靠什么?网络管理员的重要定义
- poj 2513 Colored Sticks Trie树
- java中FileOutputStream和FileInputStream类用法(总结的挺好)
- vim中输入tab符
- 博客创建
- httpclient请求方式下的泛型json转换问题
- Cocos2d-x 的内存管理
- 人工智能领域中声源定位的研究与发展------第二章 声源定位系统 (6)
- C#代码读写XML
- maven踩坑
- 1004--Java集合--Set 接口