题意:你有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 (水题二分+贪心)的更多相关文章

  1. UVaLive 7372 Excellence (水题,贪心)

    题意:给定 n 个数,要求把其中两个分成一组,然后加和,问所有的都分好,最小数是几. 析:贪心策略,最大和是小的相加,就是最优的. 代码如下: #pragma comment(linker, &quo ...

  2. UVaLive 7454 Parentheses (水题,贪心)

    题意:给定一个括号序列,改最少的括号,使得所有的括号匹配. 析:贪心,从左到右扫一下,然后统计一下左括号和右括号的数量,然后在统计中,如果有多了的右括号,那么就改成左括号,最后如果两括号数量不相等, ...

  3. UVALive 3971 Assemble(模拟 + 二分)

    UVALive 3971 题意:有b块钱.想要组装一台电脑,给出n个配件的种类,名字,价格,品质因子.若各种类配件各买一个,总价格<=b,求最差品质配件的最大品质因子. 思路: 求最大的最小值一 ...

  4. uvalive 3971 - Assemble(二分搜索 + 贪心)

    题目连接:3971 - Assemble 题目大意:有若干个零件, 每个零件给出的信息有种类, 名称, 价格, 质量,  现在给出一个金额, 要求在这个金额范围内, 将每个种类零件都买一个, 并且尽量 ...

  5. hdu 1051:Wooden Sticks(水题,贪心)

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. UVALive 3971 Assemble(二分+贪心)

    本题思路不难,但是要快速准确的AC有点儿考验代码功力. 看了大白书上的标程,大有所获. 用map和vector的结合给输入分组,这个数据结构的使用非常精美,恰到好处. #include<iost ...

  7. UVA 12124 UVAlive 3971 Assemble(二分 + 贪心)

    先从中找出性能最好的那个数, 在用钱比較少的去组合,能组出来就表明答案在mid的右边,反之在左边, #include<string.h> #include<map> #incl ...

  8. 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;现在要求老板付钱最少: ...

  9. 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 ...

随机推荐

  1. Android-基本控件和详解四种布局方式

    转自:https://www.cnblogs.com/ludashi/p/4883915.html 一.常用基本控件 1.TextView 看到Android中的TextView, 我不禁的想到了iO ...

  2. 【BZOJ1110】[POI2007]砝码Odw 贪心

    [BZOJ1110][POI2007]砝码Odw Description 在byteotian公司搬家的时候,他们发现他们的大量的精密砝码的搬运是一件恼人的工作.公司有一些固定容量的容器可以装这些砝码 ...

  3. myeclipse查看项目在本地的路径

    打开myeclipse编译器,选择项目,右键:选择properties 在这一侧的搜索框中输入:resource Location即是项目的在本地的路径. 亲测好使.

  4. [IR课程笔记]Page Rank

    主要目的: 在网络信息检索中,对每个文档的重要性作出评价. Basic Idea: 如果有许多网页链接到某一个网页,那么这个网页比较重要. 如果某个网页被一个权重较大的网页链接,那么这个网页比较重要. ...

  5. java URI 编码解码

    import java.io.UnsupportedEncodingException; /** * url转码.解码 */ public class UrlUtil { private final ...

  6. eclipse 中PlantUML的安装和使用

    安装: 填写的地址:http://hallvard.github.io/plantuml/ 安装完plantUML后,还要下载一个Graphviz https://pan.baidu.com/s/1g ...

  7. Codeforces Round #138 (Div. 2) A. Parallelepiped

    A. Parallelepiped time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. spring类扫描注入-----类扫描的注解解析器

    通过类扫描注入到容器中,这种方式,在实际开发中还是很常用的,可以看下自己的配置文件,就会发现,自己公司的项目,搞不好就是这么注入的. 起码,我发现我公司的项目就是这么干的. 下面来演示一下简单的例子: ...

  9. 坡道定点停车30cm

    坡道定点停车与起步是科目二五项必考之一,想要顺利通过该项考试,学员需要掌握两个要点,一个是车身距离右侧边线30cm以内的距离,一个是定点时机.本期,元贝小编先和大家分享半坡起步右边30公分怎么看.   ...

  10. c语言之秒数算法

    // 水仙花树:是指一个3位数字,立方和 等于该数本身 // 秒数算法:随便输入一个大于0的数,求出对应的多少小时多少分钟多少秒 #include <stdio.h> / int main ...