Dracula and Ethan
Time limit:1 Sec Memory limit:256 MB
Description
Dragon is watching competitions on TV. Every competition is held between-competitors, and surely Dragon ' s favorite. After each competition he would give a score of either 0 or 1 for each competitor and add it to the total score of this COM Petitor. The total score begins with zero. Here's a 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 are held, but this time Dragon really dislike the competition and give zeroes F Or each of the them. Finally we know the score for each one:james--0, victoria--1, Penghu--1, digo--1. All except James is the winner!
However, Dragon ' s mom comes back home again and close the TV, driving Dragon to he homework, and find out the paper with Scores of all competitors. Dragon ' s mom wants to know what 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?
Inputthe 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. Outputeach output should occupy one line. Each line should start with a "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 is watched by Dragon. Sample Input
1 3 2) 3 4
Sample outputcase #1:5
HINT
Test instructions
The result of the game has three kinds of 1,0, 0,0 to give the final score, ask you to hold at least how many times to get the final result,
Exercises
With priority queue, try to keep the result 1, 1 each time;
Code:
1#include <cstdio>2#include <cmath>3#include <cstring>4#include <ctime>5#include <iostream>6#include <algorithm>7#include <Set>8#include <vector>9#include <sstream>Ten#include <queue> One#include <typeinfo> A#include <fstream> -#include <map> -#include <stack> the typedef __int64 LL; - using namespacestd; - Const intINF = (int) 1e9+Ten; - inline ll read () + { -ll x=0, f=1; + CharCh=GetChar (); A while(ch<'0'|| Ch>'9') at { - if(ch=='-') f=-1; -Ch=GetChar (); - } - while(ch>='0'&&ch<='9') - { inx=x*Ten+ch-'0'; -Ch=GetChar (); to } + returnx*F; - } the * //******************************* $ Panax Notoginseng structSS - { the intx; +FriendBOOL operator<(ss S1,ss S2) A { the returns1.x<s2.x; + } - }; $priority_queue< SS >Q; $ intMain () - { - the intT; -Cin>>T;Wuyi intN; the intoo=1; - while(t--) Wu { -scanf"%d",&n); About for(intI=1; i<=n;i++) $ { - intx=read (); - SS xx; -xx.x=x; A Q.push (xx); + } thell ans=0; - while(!q.empty ()) $ { the SS A, B; theA=q.top (); the Q.pop (); theb=q.top (); - Q.pop (); inans+=(b.x); theB.x= (a.x-b.x); the //printf ("%d\n", b.x); About if(b.x!=0) Q.push (b); the if(Q.size () <=2) the { theb=q.top (); + Q.pop (); - //printf ("%d%d\n", B.x,ans); theans+=(b.x);Bayi Break; the } the } - while(!q.empty ()) Q.pop (); -printf"Case #%d:", oo++); theprintf"%i64d\n", ans); the } the the return 0; -}
HDU 4974 Dracula and Ethan priority queue