poj 3497 hdu 2333 hlg 1332 1511


Description

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

Input

On the first line one positive number: the number of testcases, at most 100. After that per testcase:

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

Output

Per testcase:

  • One line with one integer: the maximal possible quality.

Sample Input

1
18 800
processor 3500_MHz 66 5
processor 4200_MHz 103 7
processor 5000_MHz 156 9
processor 6000_MHz 219 12
memory 1_GB 35 3
memory 2_GB 88 6
memory 4_GB 170 12
mainbord all_onboard 52 10
harddisk 250_GB 54 10
harddisk 500_FB 99 12
casing midi 36 10
monitor 17_inch 157 5
monitor 19_inch 175 7
monitor 20_inch 210 9
monitor 22_inch 293 12
mouse cordless_optical 18 12
mouse microsoft 30 9
keyboard office 4 10

Sample Output

9

 
 
Description

在学习了一些理论基础后,MM决定要买一台电脑,搞ACM没有电脑是不行的,可是MM对电脑硬件方面一窍不通,于是找来GG帮忙,GG可是软硬件通吃,装一台电脑更是不在话下了。为了适应需求,他们打算购买电脑的各零件,然后回来自己组装。对于电脑中的每一个零件他们买且只买一个。现在的问题是每一种零件都有好多品牌,品牌下又分好多型号,不同型号的价钱不等,同时它们的质量也不一样。而整个电脑的质量取决于各零件中质量最差的那个。所以我们需要在不超出预支金额的情况下,尽量使得质量最差的那个零件的质量最大化,这样我们购买的电脑总体质量才不至于太低。

Input

输入数据的第一行有一个整数T,代表测试数据的组数。接下来有T组测试数据。

对于每组测试数据:

第一行有两个整数n和b,分别代表需要购买的零件种类,以及预支金额。

第二行到第n+1行每行代表一个零件的一些信息,这些信息以”类型 型号 价格 质量”的格式给出,它们两两之间用空格分开。这四个属性中:

“类型”为一个字符串,仅包含小写字母。不超过20个字符。

“型号”为一个字符串,包含字母,数字,下划线。不超过20个字符。

“价格”为一个正整数。

“质量”为一个正整数,数值越大则质量越高。

范围:

T ≤ 100

1 ≤ n ≤ 1 000

1 ≤ b ≤ 1 000 000 000

0 ≤ price ≤ 1 000 000

0 ≤ quality ≤ 1 000 000 000

Output

对于每组测试数据,输出一个整数并换行。这个整数代表新电脑的最大质量(即最小的质量最大是多少)

Sample Input
1
18 800
processor 3500_MHz 66 5
processor 4200_MHz 103 7
processor 5000_MHz 156 9
processor 6000_MHz 219 12
memory 1_GB 35 3
memory 2_GB 88 6
memory 4_GB 170 12
mainbord all_onboard 52 10
harddisk 250_GB 54 10
harddisk 500_FB 99 12
casing midi 36 10
monitor 17_inch 157 5
monitor 19_inch 175 7
monitor 20_inch 210 9
monitor 22_inch 293 12
mouse cordless_optical 18 12
mouse microsoft 30 9
keyboard office 4 10
Sample Output
9
就是从大到小枚举价值,复合就输出
#include<stdio.h>
#include<string.h>
#include<map>
#include<queue>
#include<math.h>
#include<set>
#include<algorithm>
#include<iostream>
using namespace std;
int ax[1005],t,n,pri,qua,ay[1005][1005],sum,az[1005][1005],b[1005],ans;
bool cmp(int a,int b)
{
    return a>b;
}
bool find(int n,int sum)
{
    int abs=sum;
    for (int i=1; i<ans; i++)
    {
        int mixn=1000000000;
        for (int j=0; j<ax[i]; j++)
        {
            if (mixn>ay[i][j]&&az[i][j]>=n)
                mixn=ay[i][j];
        }
        if (abs<0)
            break;
        abs-=mixn;
    }
    if (abs>=0)
        return true;
    else
        return false;
}
int main()
{
    char str1[21],str2[21];
    scanf("%d",&t);
    while (t--)
    {
        map<string,int> mp;
        mp.clear();
        scanf("%d%d",&n,&sum);
        memset(ax,0,sizeof(ax));
        memset(ay,0,sizeof(ay));
        memset(az,0,sizeof(az));
        ans=1;
        for (int i=0; i<n; i++)
        {
            scanf("%s %s %d %d",str1,str2,&pri,&qua);
            b[i]=qua;
            if (mp[str1]!=0)
            {
                ay[mp[str1]][ax[mp[str1]]]=pri;
                az[mp[str1]][ax[mp[str1]]]=qua;
                ax[mp[str1]]++;
            }
            else
            {
                mp[str1]=ans;
                ay[mp[str1]][ax[mp[str1]]]=pri;
                az[mp[str1]][ax[mp[str1]]]=qua;
                ans++;
                ax[mp[str1]]++;
            }
        }
        sort(b,b+n,cmp);
        if (find(b[0],sum))
        {
            printf("%d\n",b[0]);
            continue;
        }
        for (int i=1; i<n; i++)
        {
            if (b[i]==b[i-1])
                continue;
            else if (find(b[i],sum))
            {
                printf("%d\n",b[i]);
                break;
            }
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值