|
|
back to boardThis is O(1) logic - getting WA Posted by Sridhar 23 Jul 2004 07:47 See this program .. the logic is AFAIK correct .. atleast for the first 20 or so numbers. --- ( '.' is used to simulate tabs ;) int main() { ....int n; ....while(1){ ........int cnt=0; ........scanf("%d", &n); ........if (!n) break; ........if (n>1) ............n--; ........while(n) cnt++, n>>=1; ........printf("%d\n", cnt); ....} ....return 0; } --- Can anyone explain what's wrong with this logic? Re: This is O(1) logic - getting WA Posted by Died 23 Jul 2004 12:41 You can't get AC with this code because it's WRONG! 2 Died: Please, be polite! (-) Re: This is O(1) logic - getting WA Because maxima in the sequence are not log(2,n)! |
|
|