zoukankan      html  css  js  c++  java
  • poj 1953 World Cup Noise

    Description

    Background
    "KO-RE-A, KO-RE-A" shout 54.000 happy football fans after their team has reached the semifinals of the FIFA World Cup in their home country. But although their excitement is real, the Korean people are still very organized by nature. For example, they have organized huge trumpets (that sound like blowing a ship's horn) to support their team playing on the field. The fans want to keep the level of noise constant throughout the match. 
    The trumpets are operated by compressed gas. However, if you blow the trumpet for 2 seconds without stopping it will break. So when the trumpet makes noise, everything is okay, but in a pause of the trumpet,the fans must chant "KO-RE-A"! 
    Before the match, a group of fans gathers and decides on a chanting pattern. The pattern is a sequence of 0's and 1's which is interpreted in the following way: If the pattern shows a 1, the trumpet is blown. If it shows a 0, the fans chant "KO-RE-A". To ensure that the trumpet will not break, the pattern is not allowed to have two consecutive 1's in it. 
    Problem
    Given a positive integer n, determine the number of different chanting patterns of this length, i.e., determine the number of n-bit sequences that contain no adjacent 1's. For example, for n = 3 the answer is 5 (sequences 000, 001, 010, 100, 101 are acceptable while 011, 110, 111 are not).

    Input

    The first line contains the number of scenarios. 
    For each scenario, you are given a single positive integer less than 45 on a line by itself.

    Output

    The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the number of n-bit sequences which have no adjacent 1's. Terminate the output for the scenario with a blank line.

    Sample Input

    2
    3
    1

    Sample Output

    Scenario #1:
    5
    
    Scenario #2:
    2
    题意:就是问第几个斐波那契数。
    ac代码:
     1 #include<stdio.h>
     2 #include<string.h>
     3 int d[1000000];
     4 int main()
     5 {
     6     int a,b,i,j,n=0,k;
     7     for(i=1;i<50;i++)
     8     {
     9         if(i==1)
    10         d[i]=2;
    11         else if(i==2)
    12         d[i]=3;
    13         else
    14         d[i]=d[i-1]+d[i-2];
    15     }
    16     scanf("%d",&k);
    17     while(k--)
    18     {
    19         scanf("%d",&a);
    20         printf("Scenario #%d:
    %d
    
    ",++n,d[a]);
    21     }
    22 }
  • 相关阅读:
    EasyUI学习笔记之panel
    下载百度上的图片C#——输入名字就可以下载
    【转--- 数据挖掘的心得学习】
    美团推荐算法实践
    spring零配置AOP踩坑指南
    Spring学习笔记(一)
    工具类--生成随机姓名及指定长度随机字符串
    Mybatis中文模糊查询,数据库中有数据,但无结果匹配
    mybatis笔记
    code forces Watermelon
  • 原文地址:https://www.cnblogs.com/Xacm/p/3834077.html
Copyright © 2011-2022 走看看