谁贪心过的

P1090 [NOIP2004 提高组] 合并果子 / [USACO06NOV] Fence Repair G

我 ```cpp //优先队列 #include<bits/stdc++.h> using namespace std; void Cin(int &x) { char c=getchar();x=0; while(c>'9'||c<'0')c=getchar(); while(c<='9'&&c>='0')x=x*10+c-'0',c=getchar(); } struct cmp { bool operator ()(int &a,int &b) { return a>b; } }; priority_queue<int,vector<int>,cmp>q; int n; long long ans; int main() { Cin(n); int x; for(int i=1;i<=n;i++) { Cin(x); q.push(x); } int js=0; x=0; while(q.size()>0) { js++; x+=q.top(); ans+=q.top(); q.pop(); if(q.size()==0) break; if(js%2==0) { q.push(x);x=0; } } cout<<ans; return 0; } ```
by war1111 @ 2017-07-27 20:28:52


用优先队列贼简单,写的再矬都能过
by ZimHook @ 2017-07-31 16:31:42


|