Bestcoder4——Happy Three Friends(二叉堆)
来源:互联网 发布:北京计算机编程学校 编辑:程序博客网 时间:2024/05/16 11:29
本文出自: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 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 ).
If Dong-hao can achieve his goal , output "Grandpa Shawn is the Winner!"If he can not , 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!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!
AC代码:之前没有清空队列,已更改。
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; while(!q.empty()) q.pop(); if(sum > sum2) puts("Grandpa Shawn is the Winner!"); else puts("What a sad story!"); } return 0;}
0 0
- Bestcoder4——Happy Three Friends(二叉堆)
- HDU 4931 Happy Three Friends(水)
- HDOJ4931 - Happy Three Friends
- [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(水题)——BestCoder Round #4
- hdu4931 Happy Three Friends(BestCoder Round#4签到题)
- hdu 4931 Happy Three Friends(水题)
- BestCoder Round #4(Happy Three Friends-贪心)
- hdu5119——Happy Matt Friends
- 动态规划——Happy Matt Friends
- [BestCoder Round #4] hdu 4931 Happy Three Friends
- hdu 4931 /BC 4A Happy Three Friends
- hdu5119 Happy Matt Friends(dp)
- HDU 5119 Happy Matt Friends(DP)
- 背包问题
- 字符—数字转换
- 关于编译报错“dereferencing pointer to incomplete type...
- POJ 1151 Atlantis 扫描线+线段树
- Linux命令:lsof
- Bestcoder4——Happy Three Friends(二叉堆)
- python删除列表元素
- Linux命令:ifconfig
- 关于枚举的一些总结
- 找点
- JAVA WEB FILTER(过滤器)
- FPGA机器学习之龙星计划机器学习第十八堂
- Struts2中ModelDriven的陷阱及其预防
- Linux命令:route