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 |
为什么WA呢?#include<iostream.h> #include<string.h> #include<stdio.h> long b[1000][1000]; struct node{ long qi,si,vi; }; int find1(node r[],long n,long&k) { k=1; b[0][1]=r[0].qi; for(long i=1;i<n;i++){ if(r[i].qi!=r[i-1].qi){ b[0][k+1]=r[i].qi; r[i-1].qi=k; k++; } else r[i-1].qi=k; } r[n-1].qi=k; return 0; } int find2(node r[],long n,long&k) { k=1; b[1][0]=r[0].si; for(int i=1;i<n;i++){ if(r[i].si!=r[i-1].si){ b[k+1][0]=r[i].si; r[i-1].si=k; k++; } else r[i-1].si=k; } r[n-1].si=k; return 0; } int binsort1(node r[],long n) { for(long i=1;i<n;i++){ node temp=r[i]; long low=0; long high=i-1; long mid; while(low<=high){ mid=(low+high)/2; if(temp.qi<r[mid].qi) high=mid-1; else low=mid+1; } for(long j=i-1;j>=low;j--) r[j+1]=r[j]; r[low]=temp; } return 0; } int binsort2(node r[],long n) { for(long i=1;i<n;i++){ node temp=r[i]; long low=0; long high=i-1; long mid; while(low<=high){ mid=(low+high)/2; if(temp.si<r[mid].si) high=mid-1; else low=mid+1; } for(long j=i-1;j>=low;j--) r[j+1]=r[j]; r[low]=temp; } return 0; } int main() { long n; long k; long l; memset(b,0,sizeof(b)); cin>>n; node*a=new node[n]; for(long i=0;i<n;i++){ cin>>a[i].qi>>a[i].si>>a[i].vi; } binsort1(a,n); find1(a,n,k); binsort2(a,n); find2(a,n,l); b[0][0]=-1; for(i=0;i<n;i++){ b[a[i].si][a[i].qi]+=a[i].vi; } for(i=0;i<l+1;i++){ for(long j=0;j<k;j++){ cout<<b[i][j]<<" "; } cout<<b[i][k]<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator