U E D R , A S I H C RSS

Hanoi Tower Troubles Again!/조현태

느낀점 및 설명

기다리는 동안 심심해서... 간단한거 하나..
왜 아무도 않오는 거야앗!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

소스


~cpp
#include <iostream>
#include <Windows.h>
#include <vector>
#include <cmath>

using namespace std;

bool IsCanPut(int baseBallNumber, int putBallNumber)
{
	double sqrtNumber = sqrt((double)(baseBallNumber + putBallNumber));
	if (sqrtNumber == (double)(int)sqrtNumber)
		return TRUE;
	return FALSE;
}

int GetMaxBallNumber(int stickNumber)
{
	int ballCount = 0;
	vector<int> lastBallNumbers;
	lastBallNumbers.resize(stickNumber);
	while(1)
	{
		bool isPut = FALSE;
		for (register int i = 0; i < stickNumber; ++i)
		{
			if (IsCanPut(lastBallNumbers[i], ballCount + 1) || 0 == lastBallNumbers[i])
			{
				isPut = TRUE;
				lastBallNumbers[i] = ballCount + 1;
				++ballCount;
				break;
			}
		}
		if (FALSE == isPut)
			return ballCount;
	}
	
}

void main()
{
	int testCaseNumber;
	cin >> testCaseNumber;
	for (int i = 0; i < testCaseNumber; ++i)
	{
		int stickNumber;
		cin >> stickNumber;
		cout << GetMaxBallNumber(stickNumber) << endl;
	}
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:21
Processing time 0.0158 sec