This article originates from: Http://blog.csdn.net/svitter
Happy three Friends
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 0 Accepted Submission (s): 0
Problem Description
Dong-hao, Grandpa Shawn, Beautful-leg Mzry is 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.
Input
There 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).
If 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!
AC Code:
Output
#include <iostream> #include <stdio.h> #include <string.h> #include <vector> #include <map > #include <algorithm> #include <queue> #include <cmath> #define INF 0xffffff#define Lln Long long# ifdef online_judge#define FOI (file) 0#define FOW (file) 0#else#define FOI (file) freopen (file, "R", stdin); #define FOW ( File) freopen (file, "W", stdout), #endifusing namespace std;struct node{int n; BOOL operator < (const Node & A) const {return n < A.N; }};int N;int Main () {//foi ("input"); FOW ("Output"); Write your programme here int i, j, K; int n; int t; int sum, sum2; Node temp; Priority_queue <Node> Q; scanf ("%d", &t); while (t--) {for (i = 0; i < 6; i++) {scanf ("%d", &TEMP.N); Q.push (temp); } sum = 0; temp = Q.top (); sum + = TEMP.N; Q.pop (); temp = Q.top (); sum + = TEMP.N; Q.pOP (); cout << sum << endl; sum2 = 0; for (i = 0; i < 3; i++) {temp = Q.top (); Sum2 + = TEMP.N; Q.pop (); }//cout << sum2 << Endl; if (Sum > Sum2) puts ("Grandpa Shawn is the winner!"); Else puts ("What a sad story!"); } return 0;}