Dracula and Ethan

Time Limit: 1 Sec  Memory Limit: 256 MB

Description

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?

 

Input

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 (a 1,a 2,a 3,...,a n).a i(<=1000000) means the score of i-th competitor.

Output

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. 

Sample Input

1 3 2 3 4

Sample Output

Case #1: 5

HINT

 

题意:

    比赛结果有三种 1,0,    
                         0,0
                         1,1
   给出最后得分情况,问你最少举行多少次比赛可以得到最后结果,

题解:

用优先队列,每次尽量使结果保持1,1;

代码:

 #include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef __int64 ll;
using namespace std;
const int inf = (int)1E9+;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
} //******************************* struct ss
{
int x;
friend bool operator < (ss s1,ss s2)
{
return s1.x<s2.x;
}
};
priority_queue< ss >q;
int main()
{ int T;
cin>>T;
int n;
int oo=;
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int x=read();
ss xx;
xx.x=x;
q.push(xx);
}
ll ans=;
while(!q.empty())
{
ss a,b;
a=q.top();
q.pop();
b=q.top();
q.pop();
ans+=(b.x);
b.x=(a.x-b.x);
//printf("%d\n",b.x);
if(b.x!=)q.push(b);
if(q.size()<=)
{
b=q.top();
q.pop();
// printf("%d %d\n",b.x,ans);
ans+=(b.x);
break;
}
}
while(!q.empty())q.pop();
printf("Case #%d: ",oo++);
printf("%I64d\n",ans);
} return ;
}

最新文章

  1. Maven的包依赖冲突可引发java.lang.IncompatibleClassChangeError错误
  2. Statement和PreparedStatement的区别; 什么是SQL注入,怎么防止SQL注入?
  3. linux android真机测试
  4. 在word里插入图片,并设置图片的格式
  5. android ant 自动编译打包
  6. POJ 3321 Apple Tree(DFS序+线段树单点修改区间查询)
  7. BCP及自增标识列
  8. hd oj2025
  9. BZOJ 3969 Low Power 解题报告
  10. redi中删除所有的数据
  11. 遇见未知的CSS
  12. junit源码解析--测试驱动运行阶段
  13. 深度 | AI芯片终极之战
  14. Java好的的工具类:MD5
  15. 巩固python基础
  16. 手机连接wamp网页
  17. IDependency自动注册autofac
  18. node.js初识04
  19. EasyHook实现
  20. QT for Android记录

热门文章

  1. C#设计模式-1、适配器模式(Adapter Pattern)(转载)
  2. UIGestureRecognizer ios手势识别温习
  3. 10GE---超长距离的万兆以太网
  4. 在Windows的Tomcat环境下部署Solr 4.7.0
  5. ACM Computer Factory(dinic)
  6. 在Linux上使用的10种云备份方案
  7. java笔试三
  8. PHP网页数据正则采集
  9. HDOJ 1864 最大报销额(01背包)
  10. Android自定义dialogdemo