Hdoj 2333 Assemble "two points"

Source: Internet
Author: User

AssembleTime limit:3000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 479 Accepted Submission (s): 169


Problem descriptionrecently your team noticed that the computer your use of practice for programming contests are not good E Nough anymore. Therefore, you decide to buy a new computer.

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 are equal to the quality of its weakest component. Therefore, want to maximize the quality of the component with the lowest quality and while not exceeding your budget.

Inputon the first line one positive number:the number of testcases in most 100. After that per TestCase:

One line with both integers:1≤n≤1, the number of available components and 1≤b≤1, 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) which represents the The component and quality is a integer (0≤quality≤1) which represents the quality of the component (high ER is better). The strings contain only letters, digits and underscores and has a maximal length of characters.

Outputper testcase:

One line with one integer:the maximal possible quality.
Sample Input
118 800processor 3500_mhz 5processor 4200_mhz 103 7processor 5000_mhz 156 9processor 6000_mhz 219 12memory 1_GB 3mem Ory 2_gb 6memory 4_gb 12mainbord all_onboard 10harddisk 250_gb 10harddisk 500_fb © 12casing Midi-10monito  R 17_inch 157 5monitor 19_inch 175 7monitor 20_inch 9monitor 22_inch 293 12mouse cordless_optical 12mouse microsoft 9keyboard Office 4 10

Sample Output
9

Test instructions: You are going to assemble a computer and now give you different kinds of different quality and price components, your task is to choose one piece from each part without exceeding the budget, and output the largest quality of the parts extracted.

For this problem with the maximum minimum value, when there is no thought, the general use of two points;

Code:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>const int M = 1e3+5;    Using namespace Std;struct node{char name[25], type[25]; int price, quality;}    S[m];int N, b;bool Jud (int x) {int i, j, sum = 0, POS, Min;    for (i = 0; i < n;) {pos =-1;        Min = 0x7fffffff; for (j = i; J < n&&!strcmp (S[i].name, s[j].name); + + j) {if (Min > S[j].price&&s[j]            . Quality >= x) {Min = S[j].price; pos = j;        }} if (pos = =-1) return 0;        sum + = Min;    i = j;    } if (sum > B) return 0; return 1;}          int f (int left, int. right) {while (left <= right) {int mid = (left+right) >>1; if (Jud (mid)) left = mid+1;    Here if satisfied let Left = Mid+1 (because is the maximum value required) Else right = mid-1; } return right;    int main () {int t;    scanf ("%d", &t);    printf ("%d%d\n", Min, Max);        while (T--) {scanf ("%d%d", &n, &b);        int Min = 0x7fffffff, Max = -0X7FFFFFFF; for (int i = 0; i < n; + + i) {scanf ("%s%s%d", S[i].name, S[i].type, &s[i].price, &AMP;S[I].Q  uality);            Here the name and test instructions type is reversed, but does not affect the problem ...            min = min (min, s[i].quality);        max = max (max, s[i].quality);        } int ans = f (Min, Max);    printf ("%d\n", ans); } return 0;}


Hdoj 2333 Assemble "two points"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.