|
|
вернуться в форумSomeone please explain ceil() or log() function... Послано Urrong 1 сен 2011 04:07 when i was writing my first solution i used ceil and log functions for calculating how many computers get copies with available cables (without using the same number of cables as one copy before)... so i calculated "int init = (int)ceil(log((double)k) / log(2.0));" and used that in my program but i got WA#6... then i wrote my own function that does exactly the same: int getPow(int x) { int c = 0; int n = 1; while(n < x){ c++; n *= 2; } return c; } and then i got AC... can someone explain in what case the ceil and log functions would give wrong results. THANK YOU Re: Someone please explain ceil() or log() function... I also didn't got that, but this is fact: I changed my ceils and logs to self-written function and got AC. It is still challenge for me to explain, why Re: Someone please explain ceil() or log() function... I've do the same.... Maybe the problem is due to the compiler... Re: Someone please explain ceil() or log() function... Same here....and I compared my log2(x)) to (int)(log((double)x) / log(2.0)) for all x from 1 to 0x7FFFFFFF on my system and they're all identical. Re: Someone please explain ceil() or log() function... Послано Accept 24 фев 2013 08:29 You needn't use function log() or something else,You can use a const array like (2,4,8,16,32,64,128,256,512,1024....). |
|
|