|
|
back to boardWhy??? WA on test 1 test ID: 4088875 Edited by author 23.01.2012 20:49 Re: Why??? WA on test 1 Post your source code. Re: Why??? WA on test 1 #include <iostream> #include <Cmath> void main() { int n, i; long nArray; static int q[65535]; scanf("%d", &n); for(i = 0; i < n; i++) { scanf("%l", &nArray); if (floor((sqrtf(1 + 8 * (nArray - 1)) - 1) / 2) == ((sqrtf(1 + 8 * (nArray - 1)) - 1) / 2)) q[i] = 1; else q[i] = 0; } for (i = 0; i < n; i++) { printf("%d ", q[i]); } } Re: Why??? WA on test 1 Hi, Some observations: - you read a long with %l instead of %ld, which gives then WA3. The %l is not a valid scanf format specifier. On GCC the function doesn't even work (no value read) and on VS2010 the function works but returns junk. - the multiplication 8 * (nArray - 1) overflows the float type as also the long type (nArray can be at most 2^31 - 1). You should convert the multiplication to something bigger, for example the double type. Change also the sqrtf to sqrt. You'll get AC Re: Why??? WA on test 1 Thank you! I used type Double and %lf to the read. And get AC. P.S. Sorry for my bad English :( |
|
|