我的程序看起来没问题啊。。。向神犇求助!!!

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

你那里莫名其妙n++干什么
by wxl12 @ 2017-07-11 15:59:27


就一直在等待输入啊
by wxl12 @ 2017-07-11 16:00:16


而且你的算法都错了,没叫你求合并后最大值,而是合并过程中的花费 ```cpp #include <cstdio> #include <queue> #include <functional> using namespace std; int n, ans; priority_queue<long long,vector<long long>,greater<long long> >f; int main(){ scanf("%d",&n); long long tmp; while(n--){ scanf("%lld",&tmp); f.push(tmp); } long long f1,f2; while(f.size()>1){ f1=f.top(); f.pop(); f2=f.top(); f.pop(); ans+=f1+f2; f.push(f1+f2); } printf("%d",ans); return 0; } ```
by wxl12 @ 2017-07-11 16:02:52


这是链表模板,用优先队列一点技术含量都没有 ```cpp #include<iostream> #include<algorithm> using namespace std; unsigned long long sum=0; int n, b, a[10001], k; int main(){ struct node{ int data; node *next; }*head, *p, *q; cin >> n; for (int i=1;i<=n;i++) cin >> a[i]; sort(a+1,a+n+1); //for (int i=1;i<=n;i++) // cout << a[i] << ' '; head=new node; head->data=0; p=head; for (int i=1;i<=n;i++){ q=new node; q->data=a[i]; p->next=q; p=q; } p->next=head; for (int i=1;i<n;i++){ p=head; k=p->next->data+p->next->next->data; sum+=k; p->next=p->next->next->next; while (p->next->data<k && p->next!=head) p=p->next; q=new node; q->data=k; q->next=p->next; p->next=q; } cout << sum; return 0; } ```
by wxl12 @ 2017-07-11 16:04:49


```cpp #include<cstdio> #include<queue> #include<algorithm> using namespace std; priority_queue<int>q; int main(){ int n,ans=0,x; scanf("%d",&n); for(int i=0,x;i<n;i++){ scanf("%d",&x); q.push(-x); } for(int i=1;i<n;i++){ x=q.top(); ans-=q.top(); q.pop(); x+=q.top(); ans-=q.top(); q.pop(); q.push(x); } printf("%d",ans); } 做题就是要简单,方法越简单越好 ```
by ezoiHQM @ 2017-07-12 13:57:52


|