Problem E

Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 32768/16384K (Java/Other)
Total Submission(s) : 15   Accepted Submission(s) : 7
Problem Description
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.
 
Input
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.
 
Output
For every n in the input write the corresponding maximum value found.
 
Sample Input
input output
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;
}

URAL1079的更多相关文章

随机推荐

  1. win7下配置apache和php

    1.软件装备 PHP:http://php.net/downloads.php non-thread-safe是非安全线程主要与IIS搭配环境. thread-safe安全线程与Apache搭配环境. ...

  2. 浅析Activity不可见与透明

    http://blog.csdn.net/lincyang/article/details/6868582 看见标题也许你会有疑问,不可见和透明不是一个意思吗? 从字面上看,这还真是差不多.但在Act ...

  3. javascript - 清空一个 array

    我觉得javascript不容易, 许多人觉得js容易, 因为他们觉得很容易写出常用的需求, 但是当我们实际做项目的时候, 对于javascript的要求是很高的, 特别是在性能需求方面. 我写这句话 ...

  4. Android - 广播机制和Service

    花了几天,想实现定位功能,使用的是百度的服务,有时真的很无奈,就是一小小个问题,就能折腾好几天. 首先,我是在主线程(Fragment)中单独进行定位,发现不起作用. 然后我想使用Service和广播 ...

  5. Perl连接Sqlite数据库

    Sqlite是一个小巧的嵌入式关系型数据库,几乎可以嵌入所有编程语言,特别是C,C++,PHP,Perl等.这里就介绍如何用Perl连接并操作Sqlite数据库. use DBI; # perl用以操 ...

  6. oracle模糊查询效率提高

    1.使用两边加‘%’号的查询,oracle是不通过索引的,所以查询效率很低. 例如:select count(*) from lui_user_base t where t.user_name lik ...

  7. 带参数的查询防止SQL注入攻击

    把单引号替换成两个单引号,虽然能起到一定的防止SQL注入攻击的作用,但是更为有效的办法是把要拼接的内容做成“参数” SQLCommand支持带参数的查询,也就是说,可以在查询语句中指定参数: 参数的设 ...

  8. Java文件File操作一:文件的创建和删除

    一.简述 File 文件类,主要对文件进行相关操作.常用的File操作有:文件(夹)的创建.文件(夹)的删除,文件的读入和下载(复制)等: 二.文件(夹)的创建和删除 1.创建过程 实例: //cre ...

  9. framework 4.5.1安装时发生严重错误

    http://jingyan.baidu.com/article/a501d80c0a74b4ec630f5ee5.html http://jingyan.baidu.com/article/d807 ...

  10. jquery前端性能优化(持续添加。。。)

    1.选择器的使用 (1)$('#id')   使用id来定位dom元素是性能最高的方法.jQuery底层将直接调用本地方法document.getElementById().如果id直接可以找到所要对 ...