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来实现表单的显示 ...
- 開始EEPlat之旅
怎样開始EEPlat之旅 EEPlat分为社区版和商业版:功能上分为企业版和PaaS版.下面为社区企业版的開始之旅. 第一步:安装project,有两种:war包和代码project.(眼下googl ...
- Python使用Redis实现一个简单作业调度系统
Python使用Redis实现一个简单作业调度系统 概述 Redis作为内存数据库的一个典型代表,已经在非常多应用场景中被使用,这里仅就Redis的pub/sub功能来说说如何通过此功能来实现一个简单 ...
- HDU 1520 Anniversary party(DFS或树形DP)
Problem Description There is going to be a party to celebrate the 80-th Anniversary of the Ural Stat ...
- 在VPS上用Outline Manager 建立*** 增强版服务器
在VPS上用Outline Manager 建立*** 增强版服务器 原文 https://free.com.tw/google-outline/ Outline 是Google Jigsaw的一款开 ...
- 之前写的收集的一些c++代码片,算法排序,读文件,写日志,快速求积分等等
写日志: class LogFile { public: static LogFile &instance(); operator FILE *() const { return m_file ...
- Android Retrofit网络请求Service,@Path、@Query、@QueryMap、@Map...
http://blog.csdn.net/jdsjlzx/article/details/51607867
- 这是一套Java菜鸟到大牛的学习路线之高级教程,由工作了10年的资深Java架构师整理。
这是一套Java菜鸟到大牛的学习路线之高级教程,由工作了10年的资深Java架构师整理. 01-java高级架构师设计-基础深入 J2SE深入讲解 Java多 ...
- Linux系统消息队列框架Kafka单机安装配置
http://www.ithao123.cn/content-11128587.html
- Java 实现有序链表
有序链表: 按关键值排序. 删除链头时,就删除最小(/最大)的值,插入时,搜索插入的位置. 插入时须要比較O(N),平均O(N/2),删除最小(/最大)的在链头的数据时效率为O(1), 假设一个应用须 ...