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:wa? help! I have tested many cases .The results are all right. But my programme still can't pass.Would you tell me why? Thank you very much! The code is...In Reply To:wa? help! I have tested many cases .The results are all right. But my programme still can't pass.Would you tell me why? Thank you very much! The code is... Posted by:abcvisa at 2006-07-26 17:16:01 output "No solution" when there is no ans. Enlarge the size of the two arrays to more than 10^5! // This is your code. (corrected) Source Problem Id:2620 User Id:others_code Memory:980K Time:107MS Language:C++ Result:Accepted Source #include<iostream> using namespace std; /////////////////////////////////////// template<class T> void Swap(T &x, T &y) { T temp; temp = x; x = y; y = temp; } template <class T> int Partition(T a[], int p, int t) { int i=p; int j=t+1; T x=a[p]; while(1) { while(a[++i].L<x.L); while(a[--j].L>x.L); if(i>=j) break; Swap(a[i], a[j]); } a[p]=a[j]; a[j]=x; return j; } template <class T> void QuickSort(T a[], int p, int t) { if(p<t) { int q = Partition(a,p,t); QuickSort(a, p, q-1); QuickSort(a, q+1, t); } } //////////////////////////////////////////// typedef struct node { long L; long R; }node; long i,j,k,m,a,b,n,count,flag,tag; bool s[100005]; int main() { node n[100005]; cin>>m; k=0; tag=1; scanf("%ld%ld", &a,&b); while(a!=0 || b!=0) { n[k].L=a; n[k].R=b; if(a<=0 && b>=m) {tag=0; j=k;} k++; scanf("%ld%ld", &a,&b); } count = 0; if(!tag) cout<<1<<endl<<n[j].L<<' '<<n[j].R<<endl; else { flag = 0; QuickSort(n, 0, k-1); for(i=0; i<k; i++) s[i]=0; a=0; b=0; for(i=0; i<k; i++) { if(n[i].L>a) break; else { while(n[i].L<=a && i<k) { if(n[i].R>b) {b = n[i].R; j=i;} i++; } a=b; s[j]=1; count++; if(b>=m) {flag=1; break;} i--; } } if(!flag) cout<<"No solution"<<endl; else { cout<<count<<endl; for(j=0;j<k; j++) if(s[j]) cout<<n[j].L<<' '<<n[j].R<<endl; } } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator