|
|
back to boardHelp!!!! - WA on Test 14 Posted by gubbarr 11 Jun 2012 09:15 I get WA on Test 14, some can help me with this? Here's my code. #include <iostream> #include <math.h> int solve( float val_p ) { int id = 0, sqr = 0, seqCount = 0, bestCount = 9999, maxVal = val_p, n = (int)sqrt( val_p ); for( int seqID = n; seqID > n/2; seqID-- ) { id = seqID; maxVal = val_p; seqCount = 0; while( id > 0 ) { sqr = id*id; --id; if ( maxVal >= sqr ) { maxVal -= sqr; id = sqrt( float( maxVal ) ); if ( ++seqCount > bestCount ) break; } } bestCount = std::min( bestCount, seqCount ); }; return bestCount; }; int main() { unsigned int val = 0; while( std::cin >> val ) { if ( val > 60000 || val <= 0 ) break; std::cout << solve( val ) << std::endl; } return 0; } |
|
|