HDU 5835 Danganronpa
先不管神秘物品,看看把所有物品排成一排最长有多长。然后再搞搞就可以了。
数据谁了,自己造了1组数据。
T=1,n=1,a[1]=10000,ans=1
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<iostream> using namespace std; typedef long long LL; const double pi=acos(-1.0),eps=1e-8; void File() { freopen("D:\\in.txt","r",stdin); freopen("D:\\out.txt","w",stdout); } template <class T> inline void read(T &x) { char c = getchar(); x = 0;while(!isdigit(c)) c = getchar(); while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } } int T,n,a,sum,len; int main() { scanf("%d",&T); int cas=1; while(T--) { sum=len=0; scanf("%d",&n); priority_queue<int>Q; for(int i=1;i<=n;i++) { scanf("%d",&a); sum=sum+a; Q.push(a); } printf("Case #%d: ",cas++); if(sum<2) {printf("1\n"); continue;} while(Q.size()>=2) { int t1=Q.top(); Q.pop(); int t2=Q.top(); Q.pop(); len=len+2*t2; t1=t1-t2; if(t1>0) Q.push(t1); } if(len==0) len=1; if(len<=sum-len) printf("%d\n",len); else printf("%d\n",sum-len+(len-(sum-len))/2); } return 0; }