HDU 4974 Dracula and Ethan 优先队列

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 ;
}
上一篇:论文笔记(3)-Extracting and Composing Robust Features with Denoising Autoencoders


下一篇:linux系统垃圾清理