[4931]:Happy Three Friends
来源:互联网 发布:龙珠超宇宙捏脸数据 编辑:程序博客网 时间:2024/05/17 04:51
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!
解题思路:这是一道简单的题目,其实大概意思就是:对于任意输入的6个整数,最大的两个最大数之和是否能够大于剩下4个数的任意三个数(take any of 3 numbers from the last(剩下) 4 numbers )之和——–所以要与剩下的最大三个数之和比较
/* author : Yangchengfeng*/#include<stdio.h>#define N 6int main(){ int t, num[N]; while(scanf("%d", &t)!=EOF){ while(t--){ int i = 0, j, max, temp, sumG = 0, sumB = 0; for(; i<6; i++){ scanf("%d", &num[i]); } max = num[0]; for(i=0; i<6; i++){ for(j=i; j<6; j++){ if(num[j] > num[i]){ temp = num[j]; num[j] = num[i]; num[i] = temp; } } } sumG = num[0] + num[1]; sumB = num[2] + num[3] + num[4]; if(sumG > sumB){ printf("Grandpa Shawn is the Winner!\n"); } else { printf("What a sad story!\n"); } } } return 0;}
- [4931]:Happy Three Friends
- hdu 4931 Happy Three Friends
- HDU 4931 Happy Three Friends
- HDOJ 4931 Happy Three Friends
- hdoj-4931-Happy Three Friends
- hdu 4931 Happy Three Friends(水题)
- HDU 4931 Happy Three Friends(水)
- HDOJ4931 - Happy Three Friends
- [BestCoder Round #4] hdu 4931 Happy Three Friends
- hdu 4931 /BC 4A Happy Three Friends
- BestCoder Round #4(Happy Three Friends-贪心)
- HDU 4931 Happy Three Friends(水题)——BestCoder Round #4
- 【CUGBACM15级BC第四场 A】hdu 4931 Happy Three Friends
- Bestcoder4——Happy Three Friends(二叉堆)
- hdu4931 Happy Three Friends(BestCoder Round#4签到题)
- My Friends, Happy Xmas
- Happy Matt Friends (DP)
- HDU5119.Happy Matt Friends
- 前端如何实现商品规格
- 正则表达式入门
- Cortex M3存储器映射
- 使用POI操作Excel和Word
- React Native学习指南
- [4931]:Happy Three Friends
- iOS通知栏小工具开发
- Android Vertical TextView 文字竖排
- Linux通配符
- iOS开发前要知道的事儿
- 58. Length of Last Word
- Android APP设计加载使用gif动图需要注意的一般性问题
- UML类图入门,看完基本懂了怎么画图了
- java中的SuppressWarnings注解的用法