UVaLive 3971 Assemble (水题二分+贪心)
题意:你有b元钱,有n个配件,每个配件有各类,品质因子,价格,要每种买一个,让最差的品质因子尽量大。
析:很简单的一个二分题,二分品质因子即可,每次计算要花的钱的多少,每次尽量买便宜且大的品质因子。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} struct Node{
int p;
int val;
bool operator < (const Node &pp) const{
return p < pp.p;
}
Node(int pp, int v) : p(pp), val(v) { }
};
vector<Node> v[maxn];
map<string, int> mp;
int cnt; int getId(const string &s){
if(mp.count(s)) return mp[s];
return mp[s] = cnt++;
} bool judge(int mid){
int ans = 0;
for(int i = 0; i < cnt; ++i){
bool ok = false;
for(int j = 0; j < v[i].size(); ++j)
if(v[i][j].val >= mid){ ans += v[i][j].p; ok = true; break; }
if(!ok || ans > m) return false;
}
return true;
} int solve(){
int l = 1, r = (int)1e9;
for(int i = 0; i < cnt; ++i) sort(v[i].begin(), v[i].end());
while(l < r){
int mid = (l + r) >> 1;
if(judge(mid)) l = mid + 1;
else r = mid;
}
return judge(l) ? l : l-1;
} int main(){
int T; cin >> T;
while(T--){
scanf("%d %d", &n, &m);
mp.clear();
cnt = 0;
for(int i = 0; i < n; ++i) v[i].clear();
char s[25], t[25];
int p, x;
for(int i = 0; i < n; ++i){
scanf("%s %s %d %d", s, t, &p, &x);
v[getId(s)].push_back(Node(p, x));
}
printf("%d\n", solve());
}
return 0;
}
UVaLive 3971 Assemble (水题二分+贪心)的更多相关文章
- UVaLive 7372 Excellence (水题,贪心)
题意:给定 n 个数,要求把其中两个分成一组,然后加和,问所有的都分好,最小数是几. 析:贪心策略,最大和是小的相加,就是最优的. 代码如下: #pragma comment(linker, &quo ...
- UVaLive 7454 Parentheses (水题,贪心)
题意:给定一个括号序列,改最少的括号,使得所有的括号匹配. 析:贪心,从左到右扫一下,然后统计一下左括号和右括号的数量,然后在统计中,如果有多了的右括号,那么就改成左括号,最后如果两括号数量不相等, ...
- UVALive 3971 Assemble(模拟 + 二分)
UVALive 3971 题意:有b块钱.想要组装一台电脑,给出n个配件的种类,名字,价格,品质因子.若各种类配件各买一个,总价格<=b,求最差品质配件的最大品质因子. 思路: 求最大的最小值一 ...
- uvalive 3971 - Assemble(二分搜索 + 贪心)
题目连接:3971 - Assemble 题目大意:有若干个零件, 每个零件给出的信息有种类, 名称, 价格, 质量, 现在给出一个金额, 要求在这个金额范围内, 将每个种类零件都买一个, 并且尽量 ...
- hdu 1051:Wooden Sticks(水题,贪心)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- UVALive 3971 Assemble(二分+贪心)
本题思路不难,但是要快速准确的AC有点儿考验代码功力. 看了大白书上的标程,大有所获. 用map和vector的结合给输入分组,这个数据结构的使用非常精美,恰到好处. #include<iost ...
- UVA 12124 UVAlive 3971 Assemble(二分 + 贪心)
先从中找出性能最好的那个数, 在用钱比較少的去组合,能组出来就表明答案在mid的右边,反之在左边, #include<string.h> #include<map> #incl ...
- UVaLive 6698 Sightseeing Bus Drivers (水题,贪心)
题意:n个工人,有n件工作a,n件工作b,每个工人干一件a和一件b,a[i] ,b[i]代表工作时间,如果a[i]+b[j]>t,则老板要额外付钱a[i]+b[j]-t;现在要求老板付钱最少: ...
- Gym 101194D / UVALive 7900 - Ice Cream Tower - [二分+贪心][2016 EC-Final Problem D]
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...
随机推荐
- NYOJ 116 士兵杀敌(二)【线段树 单点更新】
题意:题意非常清楚: 策略:如题. 这道题就是简单的线段树应用,据说还能够用树状数组来做,等我学了之后在说吧. 代码: #include<stdio.h> #include<stri ...
- D3js-API介绍【英】
Everything in D3 is scoped under the d3 namespace. D3 uses semantic versioning. You can find the cur ...
- Asp.Net Core 初探 (三)
昨天失败的生产环境部署就先放着,明天再解决! 今天利用中午的空余时间看了一下Asp.net core 的Areas . 相对于Asp.net MVC5 以及之前的版本,asp.net core 的Ar ...
- TXT文本写入数据库
load data local infile "D:/abc.txt" into table lee; leedabao.txt内容如下,中间用Tab隔开: 2 yuanpeng ...
- 将txt文件数据存入excel表格
前言 最近使用Appium自动化在测试设备配网的情况,需要记录每次成功与否和耗时时间. 由于App不是很稳定,执行一段时间会奔溃,因此数据只能通过追加的形式写入到txt文件. 实现过程 存储在txt文 ...
- 使用Entity Framework和WCF Ria Services开发SilverLight之6:查找指定字段
对数据库表指定字段的查找,又是实际工作中的一项必要工作.SL客户端仅获取实际需要的指定的字段,好处很多,比如:有助于减少网络流量. 有两类这样的使用场景. 1:联表查询不需要外键表 在上一篇中,我们使 ...
- php 实现简单加入购物车
今天在练习购物车以及提交订单,写的有点头晕,顺便也整理一下,这个购物车相对来说比较简单,用于短暂存储,并没有存储到数据库, 购物车对于爱网购的人来说简直是熟悉的不能再熟悉了,在写购物车之前,我们首先要 ...
- 【BZOJ1520】[POI2006]Szk-Schools KM算法
[BZOJ1520][POI2006]Szk-Schools Description Input Output 如果有可行解, 输出最小代价,否则输出NIE. Sample Input 5 1 1 2 ...
- PostgreSQL Client Authentication Configuration File
PostgreSQL: Documentation: 10: 16.4. Installation Procedure https://www.postgresql.org/docs/10/stati ...
- cocos2d-js v3事件管理器
总概: 1.时间监听器(cc.EventListener)封装用户的事件处理逻辑. 2.事件管理器(cc.eventManager)管理用户注册的事件监听器. 3.事件对象(cc.Event)包含事件 ...