U E D R , A S I H C RSS

Hanoi Tower Troubles Again!/문보창

No older revisions available

No older revisions available



소감

2006-01-12 Accepted 0.092 Minimum

코드

~cpp
// 10276 - HanoiTowerTroublesAgain!
#include <iostream>
using namespace std;
#include <cmath>

#define MAX_SIZE 50

static int stick[MAX_SIZE+1];

void initStick(int n)
{
	for (int i = 1; i <= n; i++) stick[i] = 0;
}

bool isSqure(double n)
{
	double k = sqrt(n);
	return (k == floor(k)) ? true : false;
}

void process(int n)
{
	initStick(n);
	bool isGo = true;
	int number = 1;
	while (isGo)
	{
		isGo = false;
		for (int i = 1; i <= n; i++)
		{
			if (stick[i] == 0 || isSqure(stick[i] + number))
			{
				stick[i] = number++;
				isGo = true;
				break;
			}
		}	
	}
	cout << number - 1 << endl;
}	

int main()
{
	int nCase, n;
	cin >> nCase;
	for (int i = 0; i < nCase; i++)
	{
		cin >> n;	
		process(n);
	}
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:21
Processing time 0.0187 sec