U E D R , A S I H C RSS

Hanoi Tower Troubles Again!/이도현

문제

2006-01-17 11:15:29 Accepted 0.000 Minimum 56031 C++ 10276 - Hanoi Tower Troubles Again!
인기도:B(A,B,C), 성공률:높음(낮음,보통,높음), 레벨:3(1~4)

소감

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

어려웠던 점

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

코드

~cpp
// 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;
	}
}

덧글

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:21
Processing time 0.0130 sec