| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
1338大牛那学来的。贴代码。#include<stdio.h>
int min(int a,int b)
{
if(a<=b)
return a;
else return b;
}
int data[10000001];
int main()
{
int n,two=1,three=1;
data[1]=1;
for(int i=2;i<=10000000;i++)
{
data[i]=min(data[two]*2+1,data[three]*3+1);
if(data[i]==data[two]*2+1)
two++;
if(data[i]==data[three]*3+1)
three++;
}
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",data[n]);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator