SDUT 3319 优先队列 已知比分求比赛次数
来源:互联网 发布:骗淘宝运费险会封号吗 编辑:程序博客网 时间:2024/04/29 03:36
A simple water problem
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
Dragon is watching competitions on TV. Every competition is held between two competitors, and surely Dragon\'s favorite. After each
competition he will give a score of either 0 or 1 for each competitor and add it to the total score of that competitor. The total score begins
with zero. Here\'s an example: four competitors with name James, Victoria, Penghu, and Digo. First goes a competition between Penghu
and Digo, and Dragon enjoys the competition and draw both 1 score for them. Then there’s a competition between James and Victoria,
but this time Dragon draw 1 for Victoria and 0 for James. Lastly a competition between James and Digo is held, but this time Dragon
really dislike the competition and give zeroes for each of them.
Finally we know the score for each one: James--0, Victoria--1, Penghu--1, Digo--1. All except James are the Winner!
However, Dragon\'s mom comes back home again and close the TV, driving Dragon to his homework, and find out the paper with scores
of all competitors. Dragon\'s mom wants to know how many competition Dragon watched, but it\'s hard through the paper. Here comes the
problem for you, given the scores of all competitors, at least how many competitions had Dragon watched?
输入
The first line of input contains only one integer T(<=10), the number of test cases. Following T blocks, each block describe one test case.
For each test case, the first line contains only one integers N(<=100000), which means the number of competitors. Then a line contains N integers (a1,a2,a3,...,an).ai(<=1000000) means the score of i-th competitor.
输出
Each output should occupy one line. Each line should start with "Case #i: ", with i implying the case number. Then for each case just puts a line with one integer, implying the competition at least should be watched by dragon.
示例输入
132 3 4
示例输出
Case #1: 5
提示
本题题意是:已知比赛结果求比赛最少的次数.例如
三个人比赛得分是 2,3,4;每次比赛是两人一场,每人的分是1或0分..
思路.将比分进行从大到小排列,将大的a减去小的b将余下的存入队列,sum+小的分数,表示比了b场.
三个人比赛得分是 2,3,4;每次比赛是两人一场,每人的分是1或0分..
思路.将比分进行从大到小排列,将大的a减去小的b将余下的存入队列,sum+小的分数,表示比了b场.
来源
#include<iostream>#include<cstdio>#include<cstdlib>#include<queue>using namespace std;int main(){int t,T,n;while(~scanf("%d",&T)){int Case=0;while(T--){Case++;priority_queue<int,vector<int>,less<int> >Q;scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d",&t);Q.push(t);}long long sum=0;int a,b;while(!Q.empty()){a=0;b=0;a=Q.top();Q.pop();if(!Q.empty()){b=Q.top();Q.pop();sum+=b;Q.push(a-b);}}sum+=a;printf("Case #%d: %lld\n",Case,sum);}}}
0 0
- SDUT 3319 优先队列 已知比分求比赛次数
- HDU4546 比赛难度 (优先队列)
- 【优先队列】HDU4546比赛难度
- SDUT 2560 完美网络(优先队列)
- dijkstra + 优先队列 最短路 [sdut 2143]
- sdut 3345 哈夫曼编码 &&优先队列
- sdut 2506 完美网络(优先队列)
- HDU 4546 比赛难度(优先队列)
- HDU ACM 4546 比赛难度->优先队列
- 确定比赛名次(优先队列)
- HDU4546-优先队列|搜索-比赛难度
- 优先队列之加油站最小加油次数
- 【DFS】SDUT 2449 走迷宫 求走的方法次数
- hdu1285确定比赛名次(拓扑排序+优先队列)
- HDU 1285 确定比赛名次(拓扑排序+优先队列)
- HDU1285 确定比赛名次【拓扑排序】【优先队列】
- 拓扑排序模板-优先队列 hdu 1285 确定比赛名次
- 【HDU】1285--确定比赛名次(拓扑&&优先队列)
- Delphi 截取被遮挡窗口图片
- Objective-C的setter和getter
- 源码共享,希望一起互相学习
- VS2010 添加静态链接库(包括.h文件和.lib文件)以添加jsoncpp为例
- Linux中Samba详细安装
- SDUT 3319 优先队列 已知比分求比赛次数
- android中文件的保存与读取以及文件的四种操作模式
- Java中static为什么不能修饰局部变量?
- jsp的九大内置对象
- AFNetworking 使用指南
- Servlet与JSP 相关面试题
- C++Primer第五版 7.3.2节练习
- OC - NSString
- 获得桌面图标所在窗口--兼容Win7