Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Hanoitowertroublesagain/이도현

From ZeroWiki
Revision as of 01:09, 15 November 2013 by imported>smksyj
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

문제

2006-01-17 09:55:33 Accepted 0.002 Minimum 56031 C++ 10276 - Hanoi Tower Troubles Again!

소감

하노이 타워라고 보기는 좀 그런 문제다. 기웅이형이 Closed Form이 나온다는 말을 듣고 열심히 구해봤다 ㅋㅋ 결국 홀수일 때, 짝수일 때 나누어서 Closed Form을 구할 수 있었다. 또, Closed Form이 나오면 코딩은 정말 5분도 안걸린다 -.-;; 홀수 : 2n<sup>2</sup> - 1 짝수 : 2n<sup>2</sup> + 2n - 1

어려웠던 점

결국 고딩수학이 딸려서 해맸다 -.-; 계차수열 공부 다시하자 ㅋㅋ

코드

// Hanoi Tower Troubles Again
// UVa ID : 10276
#include <iostream>
using namespace std;

int process(int input);

int main()
{
	int i, testCase, input;
	cin >> testCase;

	for (i = 0; i < testCase; i++)
	{
		cin >> input;
		cout << process(input) << endl;
	}

	return 0;
}

// closed form을 구한 상태
int process(int input)
{
	// 홀수일 때
	if ((input & 1) == 1)
	{
		input++;
		input /= 2;
		return 2 * input * input - 1;
	}
	else
	{
		input /= 2;
		return 2 * input * input + 2 * input - 1;
	}
}

덧글