|
|
back to boardWA TEST#10 Help please!!! #include<iostream> using namespace std; int BinarySearch(int N,int i,int l) { int mid,p,q; p = 0; q = N-1; for(int x=0;x<l;x++) { mid = (p+q)/2; if(mid<i) p = mid +1; else q = mid -1;
}
if(mid==i) return 1; else return 0;
} int main() { int j,k=0,f,com,flag=0,first,second; cin>>f>>com; for(j=f+1;j<=10000;j=j+1) { flag = BinarySearch(j,f,com); if(flag==1) { first =j; j = j + 1; while(BinarySearch(j,f,com)==1) {j=j+1;} second = j-1; k++; flag=0; } } cout<<k<<"\n"; for(j=f+1;j<=10000;j=j+1) { flag = BinarySearch(j,f,com); if(flag==1) { first =j; j = j + 1; while(BinarySearch(j,f,com)==1) {j=j+1;} second = j-1; cout<<first<<" "<<second<<"\n"; flag=0; } } return 0; } Re: WA TEST#10 Help please!!! Are These Output correct for given inputs? 100 5 104 104 111 112 119 120 129 129 141 141 154 154 171 172 190 190 215 216 249 250 295 298 359 362 463 466 647 654 1079 1086 3231 3262 56 3 4 65 65 91 92 151 154 455 462 if they are correct,then why my soution is not accepted? Re: WA TEST#10 Help please!!! Posted by AlexF 28 Sep 2006 15:15 Try this 0 5 The right answer is 1 31 62 And your answer is 1 1 62 Good Luck! ) Re: WA TEST#10 Help please!!! I modified the code but still failing at Test#16 #include<iostream> using namespace std; int BinarySearch(int N,int i,int l) { int mid,p,q,x; p = 0; q = N-1; if(N==0) x=1; else x=0; for(;(x<l);x++) { mid = (p+q)/2;
if(mid==0)break; if(mid<i) p = mid +1; else q = mid -1;
}
if((x+1)>=l) { if(mid==i) return 1; else return 0; } else return 0; } int main() { int j,k=0,f,com,flag=0,first,second; cin>>f>>com; for(j=f+1;j<=10000;j=j+1) { flag = BinarySearch(j,f,com); if(flag==1) { first =j; j = j + 1; while(BinarySearch(j,f,com)==1&&(j<=10000)) {j=j+1;} second = j-1; k++; flag=0; } } cout<<k<<"\n"; for(j=f+1;j<=10000;j=j+1) { flag = BinarySearch(j,f,com); if(flag==1) { first =j; j = j + 1; while(BinarySearch(j,f,com)==1&&(j<=10000)) {j=j+1;} second = j-1; cout<<first<<" "<<second<<"\n"; flag=0; } } return 0; } Re: WA TEST#10 Help please!!! Edited by author 29.09.2006 19:31 |
|
|