Recently, I tried to solve problem 121C, but some weird things happened
Here is my 2 submissions
The first one gets AC, the second one gets TLE. The only difference between these 2 is in the second, i add " // " at line 77, at where the code line " cout<<" " ". Thus, if I cout<<" " at each loop, the result is OK, but if not, something happens and I get TLE. Please explain me! Thank you very much!
undefined behaviors all over the place. I wonder how one of this submissions got AC, it's kind of miracle
On line 95 you use the variable
j
without initializing it.Also you should be careful with
log10()
, it can return imprecise floating point values, and you may not get what you expect when converting the value toint
.Thanks for your response!
I forgot what happened when I used pow without epsilon last time...
But still, does cout command affect the initial value of variable? or something like this?
When you invoke undefined behavior, you can expect any weird thing to happen.
On the machine code level, this is probably because calling
operator <<
accidentally leaves a zero in the register or memory area wherej
is supposed to be, and the program appears to work.