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$的派 ...
随机推荐
- netcore 添加swagger
1.添加相应的nuget包 2.配置服务和swaggerui startup.cs 中 configureServices 中添加下面代码: //swagger services.AddSwagge ...
- navicat异常 - 1130-host ... is not allowed to connect to this MySql server
错误描述 用navicat连接数据库报错:1130-host ... is not allowed to connect to this MySql server如何处理 解决方案 1.连接服务器: ...
- macOS系统下安装ChromeDriver
1.对应的chrome浏览器需要安装对应的驱动,对应列表如下: chromedriver版本 支持的chrome版本 v2.43 v69-71 v2.42 v68-70 v2.41 v ...
- Win10镜像升级到其他版本
写在前面 必须在MSDN下载VL版本系统,一定要是VL版本的. 下载镜像,将镜像中的sources/install.wim文件放到D盘下,可以放在其他路径,在命令中的路径就不同,再在D盘创建一个ima ...
- C++-hihoCode1545-小Hi和小Ho的对弈游戏[树上Nim]
#include <set> #include <map> #include <cmath> #include <queue> #include < ...
- KindEditor 编辑器前台得使用规范
官方网址:http://www.kindsoft.net/下载网址:http://www.kindsoft.net/down.php 引入得脚本: <link href="~/Cont ...
- Python七夕记
- Unity 读取Json常用的两种方式
使用的是Litjson 1.读取本地Json public void ReadJson() { StreamReader streamReader = new StreamReader(Applica ...
- Visual Studio Code快捷键大全
原文链接:https://segmentfault.com/a/1190000007688656 常用 General 按 Press 功能 Function Ctrl + Shift + P,F1 ...
- Bayer Pattern
在刚加入工作的时候,听到最多的就是RGGB Bayer Pattern.在之前的接触中,一直默认一张图片的每个像素点有RGB三个分量,那“RGGB Bayer Pattern”究竟是什么意思.在网上查 ...