|
|
вернуться в форумWhy WA test 5 here is my algo #include <iostream> #include<algorithm> using namespace std; int main() { const int N=50000; int a[N],b[N],i,n,k,c[N],d[N],s=0; bool p=true; cin>>n; for(i=0;i<n;i++) cin>>a[i]; cin>>k; int j=k-1; for(i=0;i<k;i++) cin>>b[i]; int x=0,y=0; for(i=0;i<n;i++) c[x++]=a[i]; for(i=0;i<k;i++) d[y++]=b[i]; nth_element(c,c,c+n); nth_element(d,d,d+k); for(i=n-1;i>=0;i--) { while(j>=0) { s=d[j]+c[i]; j--; if(s==10000) { p=true; break; } else p=false; } if(p==true) break;
} if(p==true) { cout<<"YES"<<endl; } else cout<<"NO"<<endl; return 0; } Re: Why WA test 5 Ununderstandable Re: Why WA test 4 // code removed ! issue resolved !! Edited by author 13.01.2010 20:25 Re: Why WA test 4 use Quick sort: int Partition(int low,int high,int a[]) { int high_vac,low_vac,pivot; pivot=a[low]; while(high>low) { high_vac=a[high]; while(pivot<high_vac) { if(high<=low)break; high--; high_vac=a[high]; } a[low]=high_vac; low_vac=a[low]; while(pivot>low_vac) { if(high<=low)break; low++; low_vac=a[low]; } a[high]=low_vac; } a[low]=pivot; return low; } void Quicksort(int low,int high,int a[]) { int Piv_index; if(low<high) { Piv_index=Partition(low,high,a); Quicksort(low,Piv_index-1,a); Quicksort(Piv_index+1,high,a); } } then binary_search Samo es el kez quicksort Edited by author 28.01.2010 21:14 Re: Why WA test 4 Samo es test@ stugi: 3 0 0 10000 3 10000 10000 0 |
|
|