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.

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.


微信图片_20220529211312.pngOn the left you can see the diamond shape you will use, and on the right you can see the area you want to fill.


微信图片_20220529211608.png

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


微信图片_20220529211758.png

In the second test case, there is a unique way to fill the area:


微信图片_20220529211806.png

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


代码过于简单不再写


目录
相关文章
|
4月前
|
Python
编程之禅的奇幻之旅:探寻代码世界与生活万象的惊世共鸣,颠覆你的认知!
【8月更文挑战第7天】编程不仅是技术活,更融汇艺术与哲学。它启示我们在生活里追求简洁高效,如Python列表推导式的优雅;教会我们面对挑战时冷静分析,正如调试代码;体现分工合作的重要性,像模块化设计;并鼓励持续优化,提升效能。编程所蕴含的生活智慧,能引导我们创造更美好、有序的人生。
52 1
|
4月前
|
算法
编程之旅:从代码到思维的蜕变
【8月更文挑战第20天】在数字化浪潮中,编程不仅是技术的实践,更是思维的锻炼。本文探讨了编程如何影响我们的思考方式,并分享了作者个人的技术感悟和成长经历。通过深入分析编程带来的逻辑思维、问题解决能力和持续学习的重要性,文章揭示了编程与日常生活之间的紧密联系,鼓励读者以更加开放和创新的心态面对挑战。
|
6月前
|
算法 开发者
代码之美:技术感悟与编程艺术
【6月更文挑战第28天】在数字世界的构建中,代码不仅仅是冷冰冰的指令集合,更是开发者智慧与情感的结晶。本文将深入探讨编程背后的艺术性,揭示如何通过技术感悟提升代码质量,以及在日复一日的编码实践中如何保持创新与热情。
技术人修炼之道阅读笔记(九)揪头发思维
技术人修炼之道阅读笔记(九)揪头发思维
技术人修炼之道阅读笔记(八)归纳法思维
技术人修炼之道阅读笔记(八)归纳法思维
|
程序员
《长安三万里》给程序员的启发
前段时间陪孩子一起看了《长安三万里》,结合这些年自己走过的路,内心有不少感触。不论电影评价怎样,也不论事实如何,单从程序员的角度,来说说三点启发
|
文字识别 算法 NoSQL
读书分享:《程序员修炼之道:通向务实的最高境界》的思想经验
相较于全书众多的干货笔记,这篇文章是个别思想经验的总结,希望和大家交流。 ETC;DRY不仅限于编码;维护一个项目概念列表;帮助业务方理解他想要什么;防御性编程;继承税;学会沟通;小实验
读书分享:《程序员修炼之道:通向务实的最高境界》的思想经验
codeforces 1393 —— B. Applejack and Storages (思维)
codeforces 1393 —— B. Applejack and Storages (思维)
92 0
《Thinking in Bets》读书分享(2) 概率思维与从经验中学习
上一次我们分享了人的大脑本质上是不喜欢不确定性的,人是轻信的,信念又是很难改变的。 那么我们如何去解决这个问题呢?
942 0

相关实验场景

更多