【题解】A. Inscribed Figures(思维)⭐⭐

A. Inscribed Figures

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 a1,a2,…,an, each number is from 1 to 3 and ai≠ai+1 for each valid i. The i-th number represents a type of the i-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:

(i+1)-th figure is inscribed into the i-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 i from 2 to n figure i 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 n (2≤n≤100) — the number of figures.

The second line contains n integer numbers a1,a2,…,an (1≤ai≤3, ai≠ai+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

Examples
inputCopy
3
2 1 3
outputCopy
Finite
7
inputCopy
3
1 2 3
outputCopy
Infinite

Hint

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.
在这里插入图片描述




题意:

给出N个图形(1代表圆, 2代表高等于底的等腰三角形, 3代表矩形, 相邻图形不会相等), 从左到右右边的内接在左边的图形里面, 要求尽量最大而且各种平行的放, 也就是如图. 求图形中点的个数.

题解:

把那几个放的情况都列一下, 注意特判2, 1 ,3

经验小结:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef  long long LL;
const int inf = 1<<30;
const LL maxn = 110;

int n, a[maxn];
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    int ans = 0;
    bool flag = true;
    for(int i = 2; i <= n; i++){
        if(a[i]==1){
            if(a[i-1]==2) ans += 3;
            else ans += 4;
        }else if(a[i]==2){
            if(a[i-1]==1) ans += 3;
            else flag = false;
        }else{
            if(a[i-1]==1) ans += 4;
            else if(a[i-1]==2) flag = false;
        }
    }
    for(int i = 3; i <= n; i++){
        if(a[i-2]==3 && a[i-1]==1 && a[i]==2)
            --ans;
    }

    if(!flag) cout << "Infinite" << endl;
    else{
        cout << "Finite" << endl << ans << endl;
    }

	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值