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;
}菜鸟成长记
相关文章推荐
- 关于app.FragmentManager和v4包的FragmentPagerAdapter冲突
- android初学者的探索之路(Android音乐播放器)
- iPhone6/6Plus下app状态栏内容放大问题处理
- 两分钟彻底让你明白Android中onInterceptTouchEvent与onTouchEvent(图文)!
- Android中Toast的用法简介
- Unity 5 音效二 AudioMixer
- iOS调用系统通讯录获取姓名电话号码(转)
- Cocos2d-x 中与内存管理有关的宏
- Unity插件之TDTK的学习之超萌怪物(四)
- iOS-汽车品牌app
- Android三级联动筛选菜单
- Android实现计时与倒计时方法
- Android中类的设计遵循的原则
- Android实现天气预报温度/气温折线趋势图
- cocos2dx 使得单麻将(三)
- android 控件中layout_width,layout_height与onMeasure(int widthMeasureSpec, int heightMeasureSpec)
- IOS地图定位——IOS8/IOS9新特性(未完待续,欢迎给出建议、错误随时更新)
- cocos2dx-3.0(13)------SpriteBatchNode与SpriteFrameCache渲染速度
- Android Application的使用及其生命周期
- Code Forces 462B Appleman and Card Game