hdu4931 Happy three Friends (Bestcoder round#4 Registration Questions)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4931


Happy three FriendsTime limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others) Total Submission (s): Accepted submission (s):

Problem Descriptiondong-hao, Grandpa Shawn, Beautful-leg mzry are good friends. One day, they want to play a game.

There is 6 numbers on the table.

Firstly, Dong-hao can change the order of 6 numbers.

Secondly, Grandpa Shawn take the first one and the last one, sum them up as his scores.

Thirdly, Beautiful-leg Mzry take all of 3 numbers from the last 4 numbers, and sum them up as his scores.

Finally, if Grandpa Shawn ' s score is larger than Beautiful-leg Mzry ' s, Granpa Shawn wins!

If Grandpa Shawn ' s score is smaller than Beautiful-leg Mzry ' s, Granpa Shawn loses.

If the scores is equal, there is a tie.

Nowadays, it ' s really sad that Grandpa Shawn loses he love. So Dong-hao wants him-to-win (not even tie). You have a to-tell Dong-hao whether he can achieve he goal. Inputthere is a number T shows there is t test cases below. (T <= 50)

For each test case, there is 6 numbers AI (1 <= ai <= 100). Outputif Dong-hao can achieve his goal, output "Grandpa Shawn is the winner!"
If he can not and output "what a sad story!" Sample Input
31 2 3 3 2 22 2 2 2 2 21 2 2 2 3 4
Sample Output
What a sad story! What a sad story! Grandpa Shawn is the winner! Hint For the first test case, {3, 1, 2, 2, 2, 3} Grandpa Shawn can take 6 at most. But the Beautiful-leg Mzry can take 6 too. So there is a tie. For the second Test cases, Grandpa Shawn loses. For the last one, Dong-hao can arrange the numbers as {3, 2, 2, 2, 1, 4}, Grandpa Shawn can take 7, but beautiful- Leg Mzry can take 6 at the most. So Grandpa Shawn wins!
Sourcebestcoder Round #4

The code is as follows:

#include <cstdio> #include <iostream> #include <algorithm>using namespace Std;int main () {     int t;     int a[6];     while (~SCANF ("%d", &t))     {while          (t--)          {for               (int i = 0; i < 6; i++)               {                    scanf ("%d", &a[i ]);               }               Sort (a,a+6);               if (A[5]+a[4] > a[3]+a[2]+a[1])               {                    printf ("Grandpa Shawn is the winner!\n");               }               else                    printf ("What a sad story!\n");          }     }     return 0;}


Related Article

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.