ë¬¸ì œ ¶
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
기웅ì�´í˜•ì�´ 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;
}
}










