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 ...
随机推荐
- Protocol Buffers的基础说明和使用
我们開始须要使用protobuf的原因是,在处理OJ的contest模块的时候,碰到一个问题就是生成contestRank的时候.须要存储非常多信息. 假设我们採用model存储的话,那么一方面兴许假 ...
- HTTP协议学习,post于get;用Fiddler测试请求
转载 收藏于网络 1.简介: HTTP协议:Hypertext transfer protocol 超文本 传输 协议 它是TCP/IP协议集中的一个运用层协议. 用于定义WEB浏览器和WEB服务器之 ...
- canvas中遇到的理解问题
1.lineDashOffset ctx.lineDashOffset = number 描述: setLineDash 用于设置开始绘制虚线的偏移量. 数字的正负表示左右偏移. 2.createLi ...
- mini vimrc
Mini version: set enc=utf-8 ffs=unix,dos,mac lm=zh_CN.utf-8 set nu nowb nocp nowrap ru nobk sm is no ...
- Vue数据驱动表单渲染,轻松搞定form表单
form-create 具有动态渲染.数据收集.校验和提交功能的表单生成器,支持双向数据绑定.事件扩展以及自定义组件,可快速生成包含有省市区三级联动.时间选择.日期选择等17种功能组件. Github ...
- Linux下yum安装ffmpeg和使用
本文属于转载文章:转载地址是http://www.cnblogs.com/dennisit/archive/2012/12/27/2835089.html 使用Yum安装ffmpeg 打开 vi /e ...
- Mysql学习总结(4)——MySql基础知识、存储引擎与常用数据类型
1.基础知识 1.1.数据库概述 简单地说:数据库(Database或DB)是存储.管理数据的容器: 严格地说:数据库是"按照某种数据结构对数据进行组织.存储和管理的容器". 总结 ...
- 洛谷 P1914 小书童——密码
P1914 小书童——密码 题目背景 某蒟蒻迷上了“小书童”,有一天登陆时忘记密码了(他没绑定邮箱or手机),于是便把问题抛给了神犇你. 题目描述 蒟蒻虽然忘记密码,但他还记得密码是由一串字母组成.且 ...
- QQ 5.0的一些特效学习 一
虽然QQ5.0已经过去很久了,但是有些特效还是值得学习的 效果: 源码点我 导入的jar包, 一个是高版本的support.v4包,需要这个v4包中有ViewDragHelper. 我这里使用的是su ...
- Onvif开发之基础介绍篇
什么是Onvif协议,谁开启了Onvif时代? ONVIF:原意为 开放型网络视频接口论坛,即 Open Network Video Interface Forum ,是安讯士.博世.索尼等三家公司在 ...