您的位置:首页 > 移动开发

HDU 4931 Happy Three Friends(水题)——BestCoder Round #4

2015-08-16 15:16 393 查看


Happy Three Friends

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Problem Description

Dong-hao , Grandpa Shawn , Beautful-leg Mzry are good friends. One day , they want to play a game.

There are 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 any 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 are equal , there is a tie.

Nowadays , it's really sad that Grandpa Shawn loses his love. So Dong-hao wants him to win(not even tie). You have to tell Dong-hao whether he can achieve his goal.

 

Input

There is a number T shows there are T test cases below. ( T <= 50)

For each test case , there are 6 numbers Ai ( 1 <= Ai <= 100 ).

 

Output

If Dong-hao can achieve his goal , output "Grandpa Shawn is the Winner!"

If he can not , output "What a sad story!"

 

Sample Input

3
1 2 3 3 2 2
2 2 2 2 2 2
1 2 2 2 3 4

 

Sample Output

What a sad story!
What a sad story!
Grandpa Shawn is the Winner!
HintFor the first test case , {3 , 1 , 2 , 2 , 2 , 3} Grandpa Shawn can take 6 at most . But 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 most. So Grandpa Shawn Wins!

 

Source

BestCoder Round #4

 
/****************************************************/

出题人的解题思路:
Dong-Hao 肯定让 Grandpa Shawn 拿最大的两个。 Beautiful-leg Mzry 肯定会拿剩下的最大三个。 两个比较一下就行了。 当然 6! * 6 * T 枚举全排列也是可以通过的。
这是一道送分的水题,稍微讲一下题意,有6个数,Dong-Hao可以改变这6个数的顺序,Grandpa Shawn会取走第一个和最后一个,两者之和作为他的得分,而Mzry会取走剩下4个中的三个作为自己的得分,问,Dong-Hao是否有办法让Grandpa Shawn赢

我们都知道,要想Grandpa Shawn赢,肯定要让他拿走最大的两个,而Mzry为了自己赢,肯定会取走剩下4个中最大的三个,所以该题就转化成了求第一大与第二大之和是否大于第三大、第四大与第五大之和

这里面方法很多,因为题目比较水,也不深究,能解题的就是好方法

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stdlib.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 6;
const int inf = 1000000000;
const int mod = 258280327;
int s
;
int main()
{
int t,i,x,y;
scanf("%d",&t);
while(t--)
{
x=y=0;
for(i=0;i<6;i++)
scanf("%d",&s[i]);
sort(s,s+6);
for(i=1;i<4;i++)
y+=s[i];
for(;i<6;i++)
x+=s[i];
if(x>y)
puts("Grandpa Shawn is the Winner!");
else
puts("What a sad story!");
}
return 0;
}菜鸟成长记
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: