# programming-challenges Hanoi Tower Troubles Again! (110908) 题解

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <assert.h>
#include <algorithm>
#include <math.h>
#include <ctime>
#include <functional>
#include <string.h>
#include <stdio.h>
#include <numeric>
#include <float.h>

using namespace std;

bool isSquare(int num) {
int i = sqrt(num);
if (num == i*i) return true;
return false;
}

int solution(int colNum) {
vector<int> colums(colNum);
int num = 0, ans = 0;
while (true) {
num++;
bool ok = false;
for (int i = 0; i < colNum; i++) {
if (colums[i] == 0) {
colums[i] = num;
ok = true;
ans++;
break;
}
else {
if (isSquare(colums[i] + num)) {
colums[i] = num;
ok = true;
ans++;
break;
}
}
}
if (!ok) break;
}
return ans;
}

int main() {
int T = 0; cin >> T;

for (int t = 0; t < T; t++) {
int colNum; cin >> colNum;
cout << solution(colNum) << endl;
}

return 0;
}

#### Hanoi Tower Troubles Again! （找规律）

2016-02-27 19:33:22

#### zoj 1239 Hanoi Tower Troubles Again!

2015-03-08 19:44:34

#### HDU1329 Hanoi Tower Troubles Again!

2018-06-13 15:47:56

#### Hanoi Tower 汉诺塔的简单分析/C

2014-07-16 20:47:02

#### zoj1239 Hanoi Tower Troubles Again!

2013-02-21 15:53:55

#### uva10276 hanoi tower troubles again

2016-05-13 18:32:08

#### ZOJ1239 Hanoi Tower Troubles Again!

2009-07-07 20:07:00

#### Hanoi Tower问题分析

2013-08-07 23:21:19

#### 汉诺塔(Tower of Hanoi)问题的求解——利用栈与递归

2016-05-22 23:32:19

#### python 汉诺塔问题(Tower of Hanoi Puzzle)

2016-03-18 21:46:51