ZOJ 3474 Taekwondo

Source: Internet
Author: User

Taekwondo

Time Limit: 2 Seconds Memory Limit: 65536 KB

Alice is very fond of Taekwondo and he is also a member of Taekwondo Association of Zhejiang University. One day, his friends decide to compare with him. Now Alice must face all of his
Friends 'challange, that is to say, if there areTFriends, then he will takeTMatchs in just one day! Of course Alice has limited energe power, so he must carefully arrange the order ofTMatchs and take optional strategy
Win all the matchs.

Here are the rules of taekwondo match. Player must use available kicks to hit available position of his opponent's body. Different kick gets different points. To simplify this problem,
We assume that Alice will use only 3 kinds of kicks, as shown below:

  1. Axe Kick: consumeP1 energe power, get 3 points
  2. Back-Whirling Kick: consumeP2 energe power, get 2 points
  3. Turning Kick: consumP3 energe power, get 1 points

P1, P2, P3 depends
On the opponent and will be given in the input. for example, if the opponent is taller than Alice, then Axe Kick may consume more energe, but for a shorter opponent, it will be easier to use Axe Kick, thus consuming less energe.

If Alice wants to win a single match, he must getAt least 7Points and guarantee that his enenge is abveZero. After each match, Alice will have
Chance to rest, and will recoverREnerge power,RAlso depends on different opponent. Alice's initial energe power isS, And after a rest, his energe power may be moreS, Which is available. Remember that Alice can
Freely arrange the order of all the matches and he must win all the matches.

Input

The first line of the input is a single integerM, Which is the number of test cases. In each case, fisrt there are two integersT(T≤ 22) andS(S≤ 100 ),
Indicating that there areTFriends to compare with Alice and Alice's initial energe power isS. The followingTLines each contain 4 integers:PI1,PI2,PI3,RI,
As described above. (0 <=PI1,PI2,PI3,RI ≤ 100)

Output

For each case, you shoshould output one line. If Alice can win all the matches, output the max energe power he can save at last. Otherwise, output "no ".

Sample Input
22 10040 40 40 10020 70 10 1001 1040 40 40 100
Sample Output
130no
Hint

In case 1, Alice showould compare with the second person first, consume 50 energe power (2 Axe Kick and 1 Turning Kick), recover 100, then compare with the first person, consume 120 (2
Axe Kick and 1 Turning Kick), recover 100, thus the answer is 130.

Greedy, I think it is a good question. WA has done it many times, and the idea of other people can be referred to at last..

The key point lies in the selection of the competition sequence between them and their opponents. Simply sorting by the minimum consumption value, physical recovery value, or the difference between the two is incorrect, to ensure that it can compete with more opponents, we should first deal with players whose net physical strength value is positive (that is, after the completion of physical strength recovery value minus its minimum consumption value is positive ), you can sort the consumption values from small to large to ensure that all the opponents whose net physical strength value is positive can be compared once (the premise is that they can compete with the opponent, otherwise the physical strength is insufficient to jump out ), and then process the values as negative values. The values as negative values are arranged from large to small according to the reply values. For the reason, please refer to a great god's proof process.Http://hi.baidu.com/aekdycoin/item/8249c815f31c3ef9756a84dc.

The Code is as follows:

# Define test # include <iostream> # include <cstdlib> # include <cstring> # include <cstdio> # include <cmath> using namespace STD; struct power {int P1, P2, p3, R;} team [24]; struct point {int R, con;} Add [24], de [24]; int r_cmp (const void *, const void * B) {point * AA = (point *) A; point * BB = (point *) B; return AA-> r <BB-> r? 1:-1;} int con_cmp (const void * a, const void * B) {point * AA = (point *) A; point * BB = (point *) B; return AA-> con> BB-> con? 1:-1;} int differ (int I) // small data volume. You can enumerate all cases to determine the minimum consumption value {int _ min = 0x7fffffff, A, B, C; for (A = 0; A <= 3; A ++) for (B = 0; B <= 4; B ++) for (C = 0; c <= 7; C ++) if (A * 3 + B * 2 + C> = 7) _ min = min (_ min, C * team [I]. p3 + B * team [I]. p2 + A * team [I]. p1); Return _ min;} int flag [24], s; int main () {# ifdef test freopen ("in.txt", "r", stdin ); # endif int M, T; scanf ("% d", & M); While (M --) {int add_ I = 0, de_ I = 0; scanf ("% d", & T, & S); For (INT I = 1; I <= T; I ++) {scanf ("% d", & team [I]. p1, & team [I]. p2, & team [I]. p3, & team [I]. r); int ans = differ (I); If (TEAM [I]. r-ans> = 0) {Add [add_ I]. R = team [I]. r; add [add_ I ++]. con = ans;} else {de [de_ I]. R = team [I]. r; de [de_ I ++]. con = ans ;}} qsort (ADD, add_ I, sizeof (add [0]), con_cmp ); // qsort (De, de_ I, sizeof (de [0]), r_cmp) in ascending order of consumption values with positive net physical recovery values ); // If the restoration value is negative, int OK = 1 in descending order. For (INT I = 0; OK & I <add_ I; I ++) {If (S <= add [I]. con) // if the condition is not met, the system returns 0 and the challenge fails. OK = 0; S + = add [I]. r-add [I]. con ;}for (INT I = 0; OK & I <de_ I; I ++) {If (S <= de [I]. con) OK = 0; S + = de [I]. r-de [I]. con;} If (OK) printf ("% d \ n", S); else printf ("NO \ n");} return 0 ;}

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.