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;
}

原文地址:https://www.cnblogs.com/rainydays/p/2051943.html