您的位置:首页 > 其它

URAL1079

2013-11-30 22:23 253 查看
Problem E

Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/16384K (Java/Other)
Total Submission(s) : 15 Accepted Submission(s) : 7
[align=left]Problem Description[/align]

Consider the sequence of numbers ai, i = 0, 1, 2, …, which satisfies the following requirements:

a0 = 0

a1 = 1

a2i = ai

a2i+1 = ai + ai+1

for every i = 1, 2, 3, … .
Write a program which for a given value of n finds the largest number among the numbers a0, a1, …, an.

[align=left]Input[/align]

You are given several test cases (not more than 10). Each test case is a line containing an integer n (1 ≤ n ≤ 99 999). The last line of input contains 0.

[align=left]Output[/align]

For every n in the input write the corresponding maximum value found.

[align=left]Sample Input[/align]

inputoutput
5
10
0

3
4

#include<stdio.h>
int main()
{
int i,j,n,max;
int a[200005];
while(~scanf("%d",&n)&&n!=0)
{
max=0;
a[0]=0;
a[1]=1;
for(i=1;i<=n;i++)
{
a[2*i]=a[i];
a[2*i+1]=a[i]+a[i+1];
}
for(i=0;i<=n;i++)
if(a[i]>=max)
max=a[i];
printf("%d\n",max);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: