UVA 12124 Assemble(二分答案)
题目链接:https://vjudge.net/problem/UVA-12124
垃圾vjudge毁我青春!!
首先这道题是解决“最小值最大”的问题,所以要二分答案。
在这里我们二分$quality$,看是否可以组装起一台不超过$b$元的电脑。然后处理时用map映射一下。
AC代码:
#include<cstdio>
#include<iostream>
#include<map>
#include<vector>
using namespace std; const int maxn=; struct node{
int price;
int quality;
}; map<string,int> mp;
vector<node> cmp[maxn]; int n,b,cnt; int get_id(string s){
if(!mp.count(s)) mp[s]=cnt++;
return mp[s];
} bool ok(int q){
int sum=;
for(int i=;i<cnt;i++){
int cheapest=b+,m=cmp[i].size();
for(int j=;j<m;j++)
if(cmp[i][j].quality>=q) cheapest=min(cheapest,cmp[i][j].price);
if(cheapest==b+) return ;
sum+=cheapest;
if(sum>b) return ;
}
return ;
} int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&b);
mp.clear();
cnt=;
int maxq=;
for(int i=;i<n;i++) cmp[i].clear();
for(int i=;i<n;i++){
char type[],name[];
int p,q;
scanf("%s%s%d%d",type,name,&p,&q);
maxq=max(maxq,q);
cmp[get_id(type)].push_back((node){p,q});
}
int L=,R=maxq;
while(L<R){
int M=L+(R-L+)/;
if(ok(M)) L=M; else R=M-;
}
printf("%d\n",L);
}
return ;
}
AC代码
UVA 12124 Assemble(二分答案)的更多相关文章
- 【二分答案+贪心】解决“最小值最大”问题(UVa 12124 - Assemble)
Problem A - Assemble Time limit: 2 seconds Recently your team noticed that the computer you use to p ...
- 紫书 习题 11-10 UVa 12264 (二分答案+最大流)
书上写的是UVa 12011, 实际上是 12264 参考了https://blog.csdn.net/xl2015190026/article/details/51902823 这道题就是求出一种最 ...
- 紫书 例题8-10 UVa 714 (二分答案)
这道题让最大值最小, 显然是二分答案 当题目求的是最大值最小, 最小值最大, 这个时候就要想到二分答案 为什么可以二分答案呢, 因为这个时候解是单调性的, 如果简单粗暴一点 就全部枚举一遍, 验证答案 ...
- uva 12124 - Assemble
最大值最小的题: 直接用二分,比较简单: 不过我的二分老是不用好.有时间总结一下! #include<cstdio> #include<map> #include<vec ...
- 【二分答案】 【POJ3497】 【Northwestern Europe 2007】 Assemble 组装电脑
Assemble Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3171 Accepted: 1013 Descript ...
- UVa 714 Copying Books - 二分答案
求使最大值最小,可以想到二分答案. 然后再根据题目意思乱搞一下,按要求输出斜杠(这道题觉得就这一个地方难). Code /** * UVa * Problem#12627 * Accepted * T ...
- UVA 11090 Going in Cycle!!(二分答案+判负环)
在加权有向图中求平均权值最小的回路. 一上手没有思路,看到“回路”,第一想法就是找连通分量,可又是加权图,没什么好思路,那就转换题意:由求回路权值->判负环,求最小值->常用二分答案. 二 ...
- 【二分答案+贪心】UVa 1335 - Beijing Guards
Beijing was once surrounded by four rings of city walls: the Forbidden City Wall, the Imperial City ...
- UVA 12097 Pie(二分答案)
题目链接: 这道题虽然不是一道典型的二分答案题,但同样也可以用二分答案来做. 来二分面积为$area$的派,然后看看条件是否矛盾. 与其矛盾的便是$f+1$个人是否每个人都会有. 一个半径为$r$的派 ...
随机推荐
- django css文件导入,模板继承
今天写了一下模板继承 刚开始感觉还行,也挺简单的 当只有html的时候还是能继承到的,代码如下.首先在父html文件里加入 {% block content %} {% block extracss ...
- c++ 踩坑大法好 char字符,char数组,char*
1,基本语法 1,定义一个char字符: char hehe='a'; //单引号 2,定义一个由char字符组成的数组: char daqing[] = "abcd"; char ...
- LaTeX 文字带边框
1.使用framed宏包 \usepackage{framed} 可以使用verb|...|和verbatim环境而不使用cprotect宏包的cprotect命令 \begin{framed} \v ...
- python3练习100题——011
原题链接:http://www.runoob.com/python/python-exercise-example11.html 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔 ...
- c++指针实例
#include <iostream> using namespace std; int main () { ; // 实际变量的声明 int* ip; // 指针变量的声明 ip = & ...
- ASP.NET + MVC5 入门完整教程七 -—-- MVC基本工具(上)
https://blog.csdn.net/qq_21419015/article/details/80474956 这里主要介绍三类工具之一的 依赖项注入(DI)容器,其他两类 单元测试框架和模仿工 ...
- 2.10 webdriver中 js 使用
来源: 使用Webdriver执行JS小结 http://lijingshou.iteye.com/blog/2018929 selenium常用的js总结 http://www.cnblogs. ...
- 代码架构.md
代码架构 待办 昨天待办 decription decription 我的流程逻辑(异常处理方式) 1568097677501.drawio.html 29.94 KB 异常的两种处理方式 异常的两种 ...
- windows_环境变量
今天在windows下安装了openSSH,就想在windows下也添加一个服务器地址的环境变量,添加是会了,引用却不会,网上也没找到相应的文章,就自己看了看别人的bat程序,然后找到了引用变量的方法 ...
- Python的DataFrame遍历_转CSDN_J小白Y
转CSDN_J小白Y:https://blog.csdn.net/Jarry_cm/article/details/99683788 1.DataFrame.iterrows() 返回{索引,Seri ...