HDU 2333 Assemble(二分)
Assemble
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 783 Accepted Submission(s): 297
your team noticed that the computer you use to practice for programming
contests is not good enough anymore. Therefore, you decide to buy a new
computer.
To make the ideal computer for your needs, you decide
to buy separate components and assemble the computer yourself. You need
to buy exactly one of each type of component.
The problem is
which components to buy. As you all know, the quality of a computer is
equal to the quality of its weakest component. Therefore, you want to
maximize the quality of the component with the lowest quality, while not
exceeding your budget.
One line with two integers: 1 ≤ n ≤ 1 000, the number of available components and 1 ≤ b ≤ 1 000 000 000, your budget.
n
lines in the following format: “type name price quality”, where type is
a string with the type of the component, name is a string with the
unique name of the component, price is an integer (0 ≤ price ≤ 1 000
000) which represents the price of the component and quality is an
integer (0 ≤ quality ≤ 1 000 000 000) which represents the quality of
the component (higher is better). The strings contain only letters,
digits and underscores and have a maximal length of 20 characters.
One line with one integer: the maximal possible quality.
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
const int N=;
const int mod=1e9+;
int value[N],k,n,m,t;
struct Node
{
char type[];
char name[];
int cost,val;
friend bool operator<(const Node&a,const Node&b)
{
if(strcmp(a.type,b.type)==) return a.val==b.val?a.cost<b.cost:a.val>b.val;//质量相等返回价格低的
return strcmp(a.type,b.type)<;
}
}node[N];
vector<Node>v[N];
bool check(int mid)
{
ll ans=;
for(int i=;i<k;i++)
{
int pos=mod;
for(int j=;j<v[i].size();j++)
{
if(v[i][j].val>=mid) pos=min(pos,v[i][j].cost);//固定质量,每种类型娶价格最小
}
ans+=pos;
if(ans>m)return ;
}
return ;
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
k=;
for(int i=;i<n;i++)
{
v[i].clear();
scanf("%s %s %d %d",&node[i].type,&node[i].name,&node[i].cost,&node[i].val);
value[i]=node[i].val;
}
sort(value,value+n);
sort(node,node+n);
for(int i=;i+<n;i++)
{
while(i+<n&&strcmp(node[i].type,node[i+].type)==)
{
v[k].push_back(node[i]);
i++;
}
v[k].push_back(node[i]);
k++;
}
int l=,r=n-;
int mid=(r+l)>>;
while(l<=r)
{
if(check(value[mid])) l=mid+;
else r=mid-;
mid=(l+r)>>;
}
printf("%d\n",value[mid]);
}
return ;
}
HDU 2333 Assemble(二分)的更多相关文章
- UVA 10816 + HDU 1839 Dijstra + 二分 (待研究)
UVA 题意:两个绿洲之间是沙漠,沙漠的温度不同,告诉起点,终点,求使得从起点到终点的最高温度最小的路径,如果有多条,输出长度最短的路径: 思路:用最小费用(最短路径)最大流(最小温度)也能搞吧,但因 ...
- hdu 2413(最大匹配+二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2413 思路:由于要求最少的时间,可以考虑二分,然后就是满足在limit时间下,如果地球战舰数目比外星战 ...
- HDU 5884 Sort (二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5884 nn个有序序列的归并排序.每次可以选择不超过kk个序列进行合并,合并代价为这些序列的长度和.总的 ...
- hdu 1281棋盘游戏(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...
- HDU 1025 DP + 二分
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1025 求最长递增子序列,O(n^2)的复杂度超时,需要优化为O(n*logn) f[i]存储长度为i的最小 ...
- hdu 2289 要二分的杯子
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2289 大意是 一个Cup,圆台形,给你它的顶部圆的半径,底部圆的半径,杯子的高度,和此时里面装的水的体 ...
- HDU 1025 LIS二分优化
题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: ...
- HDU 5200 Trees 二分
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5200 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- hdu 2962 Trucking (二分+最短路Spfa)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962 Trucking Time Limit: 20000/10000 MS (Java/Others ...
随机推荐
- 第二十四天 框架之痛-Spring MVC(四)
6月3日,晴."绿树浓阴夏日长. 楼台倒影入池塘. 水晶帘动微风起, 满架蔷薇一院香". 以用户注冊过程为例.我们可能会选择继承AbstractController来实现表单的显示 ...
- Bitmap缓存机制
Bitmap缓存机制 载入一个bitmap到UI里面比較简单直接.可是,假设我们一次载入大量的bitmap数据的时候就变得复杂了.很多情况下(比方这些组件:ListVIew,GridView或者Vie ...
- hdu1280 前m大的数(数组下标排序)
前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- java command not found
INSTALLATION PROCEDURE ON RASPBERRY PI The remaining steps should be performed directly on the conso ...
- 微信公众号开发(二)获取AccessToken、jsapi_ticket
Access Token 在微信公众平台接口开发中,Access Token占据了一个很重要的地位,相当于进入各种接口的钥匙,拿到这个钥匙才有调用其他各种特殊接口的权限. access_token是公 ...
- python多线程理解
在发送网络请求的过程中,单个请求的速度总是有着很大的限制,而任务往往需要以更快的速度去执行,这时多线程就是一个很好地选择.python已经给我们封装好了多线程库thread和threading. th ...
- mescroll报错
1.Cannot read property 'insertBefore' of null:说明你的容器id未找到,应确认你的容器id名与你NEW的容器名一致:
- 学习——HTML5中事件
HTML5中新添加了很多事件,但是由于他们的兼容问题不是很理想,应用实战性不是太强,所以在这里基本省略,咱们只分享应用广泛兼容不错的事件,日后随着兼容情况提升以后再陆续添加分享.今天为大家介绍的事件主 ...
- 从零使用qemu模拟器搭建arm执行环境
为什么会有这篇文章 早在2011年的时候,跟当时同事一起讨论,做Linux系统开发正处于整个Linux开发中间层,没有上层的C/C++业务和数据库的开发经验.也没有底层的内核和驱动开发经验,究竟路该怎 ...
- eclipse中编码的设置
Windows-------->prefenerce------>General-------->Workspace