• Filling Diamonds——codeforces思维题


    You have integer n. Calculate how many ways are there to fully cover belt-like area of 4n−2 triangles with diamond shapes.

    Diamond shape consists of two triangles. You can move, rotate or flip the shape, but you cannot scale it.

    2 coverings are different if some 2 triangles are covered by the same diamond shape in one of them and by different diamond shapes in the other one.

    Please look at pictures below for better understanding.
    在这里插入图片描述
    On the left you can see the diamond shape you will use, and on the right you can see the area you want to fill.
    在这里插入图片描述
    These are the figures of the area you want to fill for n=1,2,3,4.
    outputstandard output
    You have integer n. Calculate how many ways are there to fully cover belt-like area of 4n−2 triangles with diamond shapes.

    Diamond shape consists of two triangles. You can move, rotate or flip the shape, but you cannot scale it.

    2 coverings are different if some 2 triangles are covered by the same diamond shape in one of them and by different diamond shapes in the other one.

    Please look at pictures below for better understanding.

    On the left you can see the diamond shape you will use, and on the right you can see the area you want to fill.
    These are the figures of the area you want to fill for n=1,2,3,4.

    You have to answer t independent test cases.

    Input
    The first line contains a single integer t (1≤t≤104) — the number of test cases.

    Each of the next t lines contains a single integer n (1≤n≤109).

    Output
    For each test case, print the number of ways to fully cover belt-like area of 4n−2 triangles using diamond shape. It can be shown that under given constraints this number of ways doesn’t exceed 1018.

    Example

    input
    2
    2
    1
    output
    2
    1
    

    Note
    在这里插入图片描述
    In the second test case, there is a unique way to fill the area:
    在这里插入图片描述
    WF退役大佬专业解释:https://www.bilibili.com/video/BV1Cg4y1871L?from=search&seid=1821321906952885250
    欢迎三连加关注
    对于第 i 个图形的方法设为ans[i],有两种方式:
    方法一:先选择最左边那个,那么剩下的选择方式就都确定了方法数为1:
    方法二:选择左上角和做下角的两块,那么这种方式就转移到了 i-1 时的方法数量,
    综上可以推出表达式 ans[i] = ans[i-1] +1;
    又因为 ans[1]=1;所以可以轻松得到 ans[i]=i;

    所以输入什么就输出什么本题就会AC


    代码过于简单不再写

  • 相关阅读:
    我决定潜心研究技术了...
    new proxy
    谷歌插件开发
    js计算不准确 解决方案
    netty中如何切包
    Spring Boot的ComponentScan原理
    解决org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token found character '@'
    深入理解js立即执行函数
    winform 将子窗体显示在父窗体的TabControl控件上
    js隐藏网页元素
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144153.html
Copyright © 2020-2023  润新知