|
|
вернуться в форумmy program,why wa?please :( #include<stdio.h> long long a[65537]; int bsearch(int b,int t,long long k) { int mid=(b+t)/2; if(b>t) { return 0; } if(k>a[mid]) { bsearch(mid+1,t,k); } else if(k<a[mid]) { bsearch(b,mid-1,k); } else return 1; } void main() { int n; long long k,i; scanf("%d",&n); for(i=1;i<=65536;i++) { a[i]=i*(i-1)/2+1; } while(n>0) { scanf("%lld",&k); printf("%d",bsearch(1,65536,k)); if(n!=1) printf(" "); n--; } } Re: my program,why wa?please :( I don't know your mistake. But I can tell you that you can find out if the given k is really 1 without binary search. It's just a simple math. It's a formula and you know the formula. k = x (x - 1) / 2 + 1 just find x and make sure that it has an positive integer value. good luck Re: my program,why wa?please :( thanks |
|
|