A. Inscribed Figures

A. Inscribed Figures
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The math faculty of Berland State University has suffered the sudden drop in the math skills of enrolling students. This year the highest grade on the entrance math test was 8. Out of 100! Thus, the decision was made to make the test easier.

Future students will be asked just a single question. They are given a sequence of integer numbers ?1,?2,…,??
, each number is from 1 to 3 and ??≠??+1 for each valid ?. The ?-th number represents a type of the ?

-th figure:

circle;
isosceles triangle with the length of height equal to the length of base;
square. 

The figures of the given sequence are placed somewhere on a Cartesian plane in such a way that:

(?+1)

-th figure is inscribed into the ?
-th one;
each triangle base is parallel to OX;
the triangle is oriented in such a way that the vertex opposite to its base is at the top;
each square sides are parallel to the axes;
for each ?
from 2 to ? figure ?

has the maximum possible length of side for triangle and square and maximum radius for circle. 

Note that the construction is unique for some fixed position and size of just the first figure.

The task is to calculate the number of distinct points (not necessarily with integer coordinates) where figures touch. The trick is, however, that the number is sometimes infinite. But that won’t make the task difficult for you, will it?

So can you pass the math test and enroll into Berland State University?
Input

The first line contains a single integer ?
(2≤?≤100

) — the number of figures.

The second line contains ?
integer numbers ?1,?2,…,?? (1≤??≤3, ??≠??+1

) — types of the figures.
Output

The first line should contain either the word “Infinite” if the number of distinct points where figures touch is infinite or “Finite” otherwise.

If the number is finite than print it in the second line. It’s guaranteed that the number fits into 32-bit integer type.
Examples
Input
Copy

3
2 1 3

Output
Copy

Finite
7

Input
Copy

3
1 2 3

Output
Copy

Infinite

Note

Here are the glorious pictures for the examples. Note that the triangle is not equilateral but just isosceles with the length of height equal to the length of base. Thus it fits into a square in a unique way.

The distinct points where figures touch are marked red.

In the second example the triangle and the square touch each other for the whole segment, it contains infinite number of points.
图像地址

#include<bits/stdc++.h>

using namespace std;

int a[200];

int main()

{

    int n,sum=0,s,flag=1;

    cin>>n;

    cin>>a[1];

    s=a[1];

    for(int i=2;i<=n;i++)

    {

        cin>>a[i];

        if(s+a[i]==5)

            flag=0;

        if(s==1)

        {

            if(a[i]==2)

                sum+=3;

            else

                sum+=4;

        }

        if(s==2)

            sum+=3;

        if(s==3)

            sum+=4;

        s=a[i];

        if(i>=3&&a[i-2]==3&&a[i-1]==1&&a[i]==2)

            sum--;

    }

    if(flag==0)

        cout<<"Infinite"<<endl;

    else

    {

        cout<<"Finite"<<endl;

        cout<<sum<<endl;

    }

    return 0;

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值