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 ...
随机推荐
- arcgis engine 获取高亮Feature、element
转自原文 arcgis engine 获取高亮Feature.element IGraphicsContainer pGraphicsC = mainAxMapControl.Map as IGra ...
- Linux同步与相互排斥应用(零):基础概念
[版权声明:尊重原创,转载请保留出处:blog.csdn.net/shallnet 或 .../gentleliu,文章仅供学习交流,请勿用于商业用途] 当操作系统进入多道批处理系统时 ...
- 简单记录一次REDO文件损坏报错 ORA-00333重做日志读取块出错
一.故障描写叙述 首先是实例恢复须要用到的REDO文件损坏 二.解决方法 1.对于非当前REDO或者当前REDO可是无活动事务使用下面CLEAR命令: 用CLEAR命令重建该日志文件SQL>al ...
- js 阻断网页选中和右键
$(document).bind("contextmenu", function () { return false; }); $(document).bind("sel ...
- POJ 3150 Cellular Automaton(矩阵高速幂)
题目大意:给定n(1<=n<=500)个数字和一个数字m,这n个数字组成一个环(a0,a1.....an-1).假设对ai进行一次d-step操作,那么ai的值变为与ai的距离小于d的全部 ...
- C++包含头文件时尖括号和双引号区别
原文链接:http://c.biancheng.net/cpp/biancheng/view/66.html 如果你还看一些别的C++教程,那么你可能很早就发现了,有些书上的#include命令写作# ...
- 动态调用WebService-获取天气
string url = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx"; string[] args ...
- SQL 查找存在某内容的存储过程
--查找存在某表名的存储过程 SELECT distinct b.name from syscomments a,sysobjects b WHERE a.id=b.id and a.TEXT LIK ...
- Linux下搭建iSCSI共享存储详细步骤(服务器模拟IPSAN存储)
一.简介 iSCSI(internet SCSI)技术由IBM公司研究开发,是一个供硬件设备使用的.可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够 ...
- 【Linux下自定义Shell终端提示符】
目录 基本转义符 字体颜色 背景颜色 移动光标 @ Linux系统终端提示符的特征由系统环境变量 PS1(Prompt String One)定义. 我们可以通过命令echo $PS1来查看当前设置, ...