Sicily 1049 Mondriaan
2016-03-21 16:25
330 查看
Constraints
Time Limit: 1 secs, Memory Limit: 32 MBDescription
Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One day, while working on his latest project, he was intrigued by the number of different ways in which he could order several objects to fill an arbitrary region. Expert as he wasin this material, he saw at a glance that this was going to be too hard, for there seemed to be innumerable ways to do this. To make his task a little easier, he decided to start with only two kinds of objects: squares with width 1 and height 1, and rectangles
with width 2 and height 1. After working on it for half an hour, he knew that even this was too much, for all of his paper was filled with pages like this. The only paper left was his toilet paper, and strange as it now seems, he continued with his task. Fortunately
the width of the toilet paper equaled the width of the rectangle, which simplified things a lot. This seemed to do just fine, for in a few minutes time, he produced the following drawing:
a particular length with squares and rectangles. Computers might come in handy in cases like this, so your task is to calculate the name of the drawing, given the length of the toilet paper. The length will be measured in the same dimension as the squares
and rectangles.
Input
The input consists of a line containing the number N (1≤N≤100) of drawings in the series. Each consecutive line consists of a number L (0≤L≤1000000) which is the length of the piece of toilet paper used for the drawing.Output
The output consists of the number that is the name for the corresponding drawing.Sample Input
5 0 1 2 3 4
Sample Output
1 2 7 2 1
Solution
简单来说就是一道找规律的题目。
a[0] = 1;
a[1] = 2;
a[2] = 2*a[1] + 3*a[0] = 7;
a[3] = 2*a[2] + 3*a[1] + 2*a[0] = 22;
a[4] = 2*a[3] + 3*a[2] + 2*a[1] + 2*a[0] = 71;
规律很明显了,然后化简一下就是a
= 3*a[n-1] + a[n-2] - a[n-3] for (n >= 3)。这个规律是通过画图找出来的,因为每多加一行,就多出一种不可切分的方案,上下颠倒一下就算完了。预处理全部的答案,然后按输入输出对应的答案即可。这里只要求最后一个数字,保存最后一个数字即%10,其中因为有减法,可能存在负数,特殊处理一下就好。
#include <stdio.h>
int a[1000005];
void init()
{
a[0] = 1;
a[1] = 2;
a[2] = 7;
for (int i = 3; i < 1000005; ++i)
{
a[i] = (3*a[i-1] + a[i-2] - a[i-3]) % 10;
if (a[i] < 0) a[i] += 10;
}
}
int main()
{
int n;
init();
scanf("%d", &n);
while (n --)
{
int t;
scanf("%d", &t);
printf("%d\n", a[t]);
}
}
相关文章推荐
- sicily 1020. Big Integer
- soj1041. Pushing Boxes
- Sicily 1046, Plane Spotting
- SICILY 1934 移动小球
- 1920. Divide The Stones
- 1801. Reading books
- 1874. Three little pigs
- 导游 解题报告(Floyd-Warshall 算法)
- Sicily 1121. Tri Tiling
- Sicily 1090. Highways
- Sicily 1155. Can I Post the lette
- Sicily 1200. Stick
- Sicily 1342. 开心的金明
- Sicily 1153. 马的周游问题
- Sicily 1171. The Game of Efil
- 1007[To and Fro]
- 1014[Specialized Four-Dig]
- 1024[MJ, Nowhere to Hide]
- 1036[Crypto Columns]
- 1147[谁拿了最多奖学金]