題意:
(from luckycat)
解法:
just do it,直接模擬過程竟然不會太久XD。
TAG: ad hoc
注意:
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tittle: 10276 - Hanoi Tower Troubles Again! | |
* Author: Cheng-Shih, Wong | |
* Date: 2015/06/03 | |
*/ | |
// include files | |
#include <bits/stdc++.h> | |
using namespace std; | |
// definitions | |
#define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i ) | |
#define clr(x,v) memset( x, v, sizeof(x) ) | |
typedef vector<int> VI; | |
typedef vector<VI> VVI; | |
// declarations | |
// functions | |
bool isSqrNum( int x ) | |
{ | |
int v = sqrt(x); | |
return (v*v==x || (v+1)*(v+1)==x); | |
} | |
// main function | |
int main( void ) | |
{ | |
// init | |
VVI buc; | |
bool found; | |
int ans[55]; | |
int n, t; | |
FOR( i, 1, 10000 ) { | |
found = false; | |
FOR( j, 0, buc.size()-1 ) { | |
if( isSqrNum(buc[j].back()+i) ) { | |
buc[j].push_back(i); | |
found = true; | |
} | |
} | |
if( !found ) { | |
ans[buc.size()] = i-1; | |
buc.push_back(VI()); | |
buc.back().push_back(i); | |
} | |
if( buc.size() >= 51 ) break; | |
} | |
// input | |
scanf( "%d", &t ); | |
while( t-- ) { | |
scanf( "%d", &n )==1; | |
printf( "%d\n", ans[n] ); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言
任何意見都樂意傾聽