Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
菜鸟求救。。。为何RE代码如下,希望大牛帮助!!!!! 蟹蟹~ #include<cstdio> #include<algorithm> using namespace std; struct Node { int b; int f; int s; }; struct Node a[100000],l; int x[2500000],v[2500000]; void verifyheap(int i,int n) { int x,t; t=i; if(i*2+1<n) { if(a[2*i+1].s/(v[a[2*i+1].f]-v[a[2*i+1].b])<a[t].s/(v[a[t].f]-v[a[t].b])) { t=2*i+1; } } if(i*2+2<n) { if(a[2*i+2].s/(v[a[2*i+2].f]-v[a[2*i+2].b])<a[t].s/(v[a[t].f]-v[a[t].b])) { t=2*i+2; } } if(t!=i) { l=a[i]; a[i]=a[t]; a[t]=l; verifyheap(t,n); } } void build(int n) { int i; for(i=(n-1)/2;i>=0;i--) { verifyheap(i,n); } } int main() { int n,i,j,k,s,m; scanf("%d",&n); m=0; for(i=0;i<n;i++) { scanf("%d%d",&x[i],&v[i]); for(j=0;j<i;j++) { if(v[j]>v[i]&&x[i]>x[j]) { a[m].b=i; a[m].f=j; a[m].s=x[i]-x[j]; m++; } if(v[i]>v[j]&&x[j]>x[i]) { a[m].b=j; a[m].f=i; a[m].s=x[j]-x[i]; m++; } } } build(m); printf("%d\n",m); k=min(m,10000); while(k>0) { printf("%d %d\n",a[0].f+1,a[0].b+1); for(j=1;j<k;j++) { a[j].s-=(a[0].s/(v[a[0].f]-v[a[0].b]))*(v[a[j].f]-v[a[j].b]); } a[0]=a[k-1]; k--; verifyheap(0,k); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator