思路:二分,就是在不超过b的预算下,使得品质的最小值最大化。关键还是判断函数吧。

   假设答案为x,判断函数,就是每一个种类的配件的品质最基本的品质要大于x,然后找出最小的值。这样的配件品质之和的价格要小于b元。

   则表明x是答案之一。但是,不一定是最优答案。最后答案就要看二分的方向了。

#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
const int maxn = 1e3 + ;
int cnt;
map<string, int>ss;
int id(string x){
if (!ss.count(x))ss[x] = cnt++;
return ss[x];
}
struct node{ int x, y; };
vector<node>comp[maxn];
int t, n, b; //品质不小于x的组件能否组装为不超过b的电脑
bool ok(int x){
int sum = ;
for (int i = ; i < cnt; ++i){
int pest = b + , m = comp[i].size();
for (int j = ; j < m;++j) //找大于x的最小值
if (comp[i][j].y >= x)pest = min(pest, comp[i][j].x);
if (pest == b + )return ;
sum += pest;
if (sum>b)return ;
}
return ;
} int main(){
cin >> t;
while (t--){
cin >> n >> b;
//初始化
cnt = ;
for (int i = ; i < n; ++i)comp[i].clear();
ss.clear(); int maxq = ;
for (int i = ; i < n; ++i){
//初始化
string type, name; int x, y;
cin >> type >> name >> x >> y; maxq = max(maxq, y);
comp[id(type)].push_back(node{ x, y });
}
int L = , R = maxq;
while (L < R){
// cout << "L=" << L << " R=" << R << endl;
int M = L + (R - L + ) / ;
if (ok(M))L = M; else R = M - ;
}
cout << L << endl;
}
return ;
}

最新文章

  1. C++整数转字符串的一种方法
  2. java spring 配置文件的读取
  3. base64与byte[]之间转换
  4. zabbix 3.0.4 Nginx 性能监控
  5. .net学习笔记---webconfig的读与写
  6. iOS 开发之 Xcode6 创建真机调试证书
  7. [Angular2 Form] Use RxJS Streams with Angular 2 Forms
  8. 4.2 CUDA Reduction 一步一步优化
  9. 配置android source 在ubuntu中编译环境
  10. Android全部权限详解(manifest.xml)
  11. LeetCode OJ 292.Nim Gam148. Sort List
  12. Android中微信抢红包助手的实现
  13. JavaWeb的国际化(17/4/8)
  14. (转)Spark性能优化:资源调优篇
  15. C++之标准输入输出
  16. PAT1055:The World&#39;s Richest
  17. zabbix使用客户端和不使用客户端监控指定端口
  18. canvas绘制圆图输出图片格式
  19. Python全栈开发之路 【第四篇】:Python基础之函数
  20. 控件_TimePicker

热门文章

  1. 页面结构化在 Android 上的尝试
  2. webpack4打包nodejs项目进阶版——多页应用模板
  3. Vue(day4)
  4. 前端技术大行其道,再不拥抱TypeScript你就老了!
  5. PHP内核之旅-4.可变长度的字符串
  6. linux(centos)上安装mysql教程,为需要远程登录的用户赋予权限
  7. golang的cms
  8. 中缀表达式得到后缀表达式(c++、python实现)
  9. ArticleRemoveDelDialog【基于AlertDialog的回收删除对话框】
  10. DotNetCore跨平台~聊聊中间件