例题12组装电脑
来源:互联网 发布:台湾高铁网络订票系统 编辑:程序博客网 时间:2024/04/29 14:14
提交传送门:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=13338
主要是map的使用和二分答案。
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <algorithm>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mem(a) memset(a, 0, sizeof(a))
#define eps 1e-5
#define INF 0x3f3f3f3f
using namespace std;
int cnt;
map<string ,int > id;
int ID(string s)
{
if(!id.count(s))
id[s]=cnt++;
return id[s];
}
const int maxn=1000+5;
struct node
{
int price;
int quality;
};
int n,b;
vector<node> comp[maxn];
bool ok(int q)
{
int sum=0;
for(int i=0;i<cnt;i++)
{
int cheapest=b+1;
int m=comp[i].size();
for(int j=0;j<m;j++)
if(comp[i][j].quality>=q)
cheapest=min(cheapest,comp[i][j].price);
if(cheapest==b+1)
return false;
sum+=cheapest;
if(sum>b)
return false;
}
return true;
}
int main()
{
int T;
cin>>T;
while(T--)
{
cin>>n>>b;
cnt=0;
for(int i=0;i<n;i++)
comp[i].clear();
id.clear();
int maxq=0;
for(int i=0;i<n;i++)
{
char type[30],name[30];
int x,y;
cin>>type>>name>>x>>y;
maxq=max(maxq,y);
comp[ID(type)].push_back((node){x,y});
}
int l=0;
int r=maxq;
while(l<r)
{
int M=(l+r+1)/2;
if(ok(M))
l=M;
else
r=M-1;
}
cout<<l<<endl;
}
}
- 例题12组装电脑
- 例题1.12 组装电脑 UVa12124
- 例题1.12 组装电脑 Assemble UVALive
- 电脑组装
- 组装电脑
- 组装电脑配置---推荐
- 电脑组装参考方案
- 怎么组装电脑
- 组装电脑的配置
- 电脑组装视频
- uva 12124 组装电脑
- LA3971组装电脑
- uva12124 组装电脑
- LA 3971 组装电脑
- LA 3971 组装电脑
- UVALive 3971 组装电脑
- 组装电脑步骤
- 电脑组装配置单及组装电脑图文详细教程
- MySQL 服务无法启动 ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
- DataSet用法详细
- 《java入门第一季》之面向对象(内部类到底在哪里?)
- Python学习笔记:元组(tuple)有关内容
- Faster-rcnn
- 例题12组装电脑
- Runtime的初步认识——结构体与类
- android studio 学习笔记之 生成签名APK
- d-s证据理论
- 关于NSTimer
- 将博客搬至CSDN
- 《Swift入门》ubuntu下编译运行Swift开发的Web后端示例
- 如何创建google api cient id & api key 图文版本
- 从零开始学Hadoop----浅析HDFS(一)