zoukankan      html  css  js  c++  java
  • 第一轮 H

    Flags
    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
    Submit Status
    
    Description
    On the Day of the Flag of Russia a shop-owner decided to decorate the show-window of his shop with textile stripes of white, blue and red colors. He wants to satisfy the following conditions:
    
        Stripes of the same color cannot be placed next to each other.
        A blue stripe must always be placed between a white and a red or between a red and a white one.
    
    Determine the number of the ways to fulfill his wish.
    Example. For N = 3 result is following:
    Problem illustration
    
    Input
    N, the number of the stripes, 1 ≤ N ≤ 45.
    
    Output
    M, the number of the ways to decorate the shop-window.
    
    Sample Input
    input	output
    
    3
    
    4
    
    放第i个的时候,有两种方法:
          一、在第i 个上放上与i-1个相反的颜色(第i-1个是红色,则放白色,否则放红色);
          二、将第i-1个的颜色改成蓝色的;
    综合上述的两种情况:ans[i]=ans[i-1]+ans[i-2]
    /*************************************************************************
    	> File Name: h.cpp
    	> Author:yuan 
    	> Mail: 
    	> Created Time: 2014年11月09日 星期日 20时41分18秒
     ************************************************************************/
    
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cstdlib>
    #include<cmath>
    using namespace std;
    long long ans[50];
    int n;
    int main()
    {  
        ans[1]=ans[2]=2;ans[0]=0;
        for(int i=3;i<=45;i++)
        {
            ans[i]=ans[i-1]+ans[i-2];
        }
        while(~scanf("%d",&n)){
            printf("%I64d
    ",ans[n]);
        }
        return 0;
    }
    
    


  • 相关阅读:
    httpclient在获取response的entity时报异常
    SpringCloud项目,接口调用返回http 500
    使用maven插件生成grpc所需要的Java代码
    win10 无法修改默认程序 默认打开方式的解决方法
    mock.js中新增测试接口无效,返回404
    echarts的pie图中,各区块颜色的调整
    HashMap源码注释翻译
    netty学习记录2
    netty学习记录1
    Java-JNA使用心得2
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4254399.html
Copyright © 2011-2022 走看看