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 ...
随机推荐
- 找出一堆数中最小的前K个数
描写叙述: 给定一个整数数组.让你从该数组中找出最小的K个数 思路: 最简洁粗暴的方法就是将该数组进行排序,然后取最前面的K个数就可以. 可是,本题要求的仅仅是求出最小的k个数就可以,用排序能够但显然 ...
- JUnit中assertEquals和assertSame方法的不同
1)提供的接口数量不完全相同. assertEquals支持boolean,long,int等等java primitiveType变量.assertSame只支持Object. 2)比较的逻辑不同, ...
- 添加使用session回话属性
@SessionAttributes("nowUser") nowUser :id/userName/password public String delectMsg(int id ...
- XML结构,写到TreeView树上
http://blog.csdn.net/ztzi321/article/details/44077563
- org.mybatis.spring.mapper.MapperScannerConfigurer$Scanner$1
不能加载或找不到 org.mybatis.spring.mapper.MapperScannerConfigurer$Scanner$1 经查证,是mybatis-spring-xxx.jar 这个版 ...
- c#多线程操作测试(阻塞线程,结束任务)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- C#一些延时函数
sleep延时方法: System.Threading.Thread.Sleep(); //毫秒 在C#窗口程序中,如果在主线程里调用Sleep,在Sleep完成之前, 界面呈现出假死状态,不能响应任 ...
- OpenSUSE Leap 42.3下通过Firefox Opera Chromium浏览器直接执行java应用程序(打开java jnlp文件)实现在服务器远程虚拟控制台完成远程管理的方法
远程虚拟控制台依赖于java运行环境(jre),在通过浏览器打开链接前,系统必须安装jre环境,远程管理控制台其实就是一个java程序,打开相应的网站会下载一个jnlp(java网络加载协议)的文件, ...
- css line-height详解
行高指的是文本行的基线间的距离(更简单来说,行高是指文字尺寸与行距之间的和). 而基线(Base line),指的是一行字横排时下沿的基础线, 基线并不是汉字的下端沿,而是英文字母x的下端沿,同时还有 ...
- iOS基本UI控件总结
包括以下几类: //继承自NSObject:(暂列为控件) UIColor *_color; //颜色 UIImage *_image; //图像 //继承自UIView:只能相应手势UI ...