poj2591

暴力做就可以过。

View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
using namespace std;

#define maxn 10000005

int ans[maxn];

int main()
{
// freopen("t.txt", "r", stdin);
int p1, p2;
ans[
0] = 1;
p1
= 0;
p2
= 0;
for (int i = 1; i <= 10000000; i++)
{
ans[i]
= min(ans[p1] * 2 + 1, ans[p2] * 3 + 1);
if (ans[i] == ans[p1] * 2 + 1)
p1
++;
if (ans[i] == ans[p2] * 3 + 1)
p2
++;
}
int n;
while (scanf("%d", &n) != EOF)
printf(
"%d\n", ans[n - 1]);
return 0;
}

posted @ 2011-05-20 14:06  金海峰  阅读(170)  评论(0编辑  收藏  举报