hdu4931 Happy Three Friends(BestCoder Round#4签到题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4931

Happy Three Friends

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

Total Submission(s): 150    Accepted Submission(s): 128

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!

Hint

For 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

代码如下:

#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;
}

hdu4931 Happy Three Friends(BestCoder Round#4签到题)

时间: 2024-10-18 08:35:53

hdu4931 Happy Three Friends(BestCoder Round#4签到题)的相关文章

BestCoder Round #1 第一题 逃生

// 等了好久,BESTCODER 终于出来了..像咋这样的毕业的人..就是去凑凑热闹// 弱校搞acm真是难,不过还是怪自己不够努力// 第一题是明显的拓扑排序,加了了个字典序限制而已// 用优先队列就可以搞定了#include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> #include <vector> #include <map>

BestCoder Round #1 第二题 项目管理

// 第二题 我记得很久很久很久以前看过这样的题目,忘记是哪的区域赛了 // 记得有人说和节点度数有关,我记不清了,反正当时完全不懂 // 然后我想了想,估计就是更新节点度数有关,YY出来可能只要更新相邻节点度数更大或更小的就可以了 // 复杂度不知道多少,就是提交了试试,15MS就过了 // 看来就是这样了 // 具体就是求出每个节点度数,然后每次更新时,只要更新与自己相连,但度数比自己大的 // 查询时把度数自己大的节点累加的值加上就可输出,具体看代码比较清楚 // 也就做得来这2题了(见识

ACM学习历程—HDU5269 ZYB loves Xor I(位运算 &amp;&amp; dfs &amp;&amp; 排序)(BestCoder Round #44 1002题)

Problem Description Memphis loves xor very musch.Now he gets an array A.The length of A is n.Now he wants to know the sum of all (lowbit(Ai xor Aj) (i,j∈[1,n]) We define that lowbit(x)=2^k,k is the smallest integer satisfied ((x and 2^k)>0)Specially,

BestCoder Round #14 B 题 Harry And Dig Machine 【TSP】

题目:Harry And Dig Machine 哈哈  终于涨边粉色了,不容易呀.顺便写一道题解吧 题意:给一个m*n的矩阵,然后其中最多由10个有值,求总左上角把所有的值都拿上回到左上角的最小步数. 标准的TSP回到原点问题,需要先预处理出图来,然后TSP即可. AC代码: #include <cstdio> #include <algorithm> #include <cstring> #include <string> #include <io

BestCoder Round #31 B题

beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 136    Accepted Submission(s): 78 Problem Description Let A=∑ni=1ai?10n?i(1≤ai≤9)(n is the number of A's digits). We call A as "

从lca到树链剖分 bestcoder round#45 1003

bestcoder round#45 1003 题,给定两个点,要我们求这两个点的树上路径所经过的点的权值是否出现过奇数次.如果是一般人,那么就是用lca求树上路径,然后判断是否出现过奇数次(用异或),高手就不这么做了,直接树链剖分.为什么不能用lca,因为如果有树退化成链,那么每次询问的复杂度是O(n), 那么q次询问的时间复杂度是O(qn) 什么是树链剖分呢? 就是把树的边分成轻链和重链 http://blogsina.com.cn/s/blog_6974c8b20100zc61.htmlh

HDU-5086-Revenge of Segment Tree (BestCoder Round #16)

Revenge of Segment Tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 205    Accepted Submission(s): 83 Problem Description In computer science, a segment tree is a tree data structure for st

BestCoder Round #8 A,B,C

BestCoder Round #8 题目链接 A:签到题不多说 B:矩阵快速幂,奇数项的式子为f(n) = 4 * f(n - 1) + 1,偶数项是奇数项的两倍,然后构造矩阵为4 1 0 1进行快速幂即可 C:dp+树状数组加速,dp[i][j]表示以i为结尾长度为j的种数,然后把数字离散化掉,每次状态转移都需要从前一个区间和转移过来,所以可以利用树状数组维护 代码: A: #include <cstdio> #include <cstring> #include <al

BestCoder Round #91

传送门:http://acm.hdu.edu.cn/search.php?field=problem&key=BestCoder+Round+%2391&source=1&searchmode=source A题:给你n种字母,每种字母有个权值vali,共cnti个,现在让你在里面挑出任意数量的字符,组合成一个字符串,该字符串的权值的计算方式为val1*1+val2*2+--+valn*n,让你输出字符串最大的权值是多少.这题很容易会有一个错误的贪心,就是把val为负的舍去,然后v