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$的派 ...
随机推荐
- mybatis一级缓存和二级缓存(三)
缓存详细介绍,结果集展示 https://blog.csdn.net/u013036274/article/details/55815104 配置信息 http://www.pianshen.co ...
- Linux下搭建PHP环境的参考文章小记
之前也在Linux上安装过两次,但是当我再次需要安装时,还是很多不懂的地方,于是记下此篇,以防下次再费经心思找到不合适的文章,瞎折腾. 通过参考这几篇文章,成功的安装好了自己的PHP(LNMP)环境. ...
- Myeclipse连接Mysql数据库时报错:Error while performing database login with the pro driver:unable
driver template: Mysql connector/j(下拉框进行选择) driver name: 任意填,最好是数据库名称,方便查找 connection URL: jdbc:mysq ...
- (转)正则表达式:string.replaceAll()中的特殊字符($ \)与matcher.appendReplacement
string.replaceAll中的特殊字符 string.replaceAll(String regex, String replacement)中的replacement参数即替换内容中含有特殊 ...
- ubuntu系统定时运行 crontab
1,crontab是个啥? ubuntu系统自带cron工具,cron是一个系统上的定时工具,用它的好处在于,不同的程序可以用同一个计时器,这样就省得不同程序各自sleep了,另外它还支持比较多的个性 ...
- cc.rectContainsPoint使用中发现的问题
cc.rectContainsPoint(rect, point);此中rect常用node.getBoundingBox()方法取得,而这个方法通过node的x,y和width,height算得.也 ...
- 谷歌浏览器安装jsonview
1.下载JsonView扩展程序压缩包 下载链接:https://pan.baidu.com/s/1B0IkrHHyTiYtwJEGE_halA 提取码:myi6 2.解压这个压缩包 3.打开谷歌浏览 ...
- g++运行c++程序提示main()找不到
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start': (.text+0x20) ...
- 页面回显与URL模板映射
一.页面回显 对于需要返回界面的数据,可以将后台封装好的数据回显至原始jsp界面中. 举个例子: User.java package com.zk.data; public class User { ...
- java简单学生成绩管理系统
题目要求: 一. 数据结构要求:(5 分) 1.定义 ScoreInformation 类,其中包括七个私有变量(stunumber, name, mathematicsscore, englishi ...