Educational Codeforces Round 64 (Rated for Div. 2)ABC

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
inputCopy
3
2 1 3
outputCopy
Finite
7
inputCopy
3
1 2 3
outputCopy
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.

题意: 有三种图形,1表示圆,2表示等腰三角形,3表示正方形。现在有n个1~3的数组成,分别代表三个图形,且xi内切于xi-1,问他们一共有多少个点相切。
思路: 直接暴力,特判3 1 2的情况,因为此时正方形 圆 等腰三角形同时切于一个点

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,ans=0,flag=0;
    int a[111];
    cin>>n;
    for(int i=0;i<n;i++)    cin>>a[i];
    for(int i=1;i<n;i++){
        if(a[i]==2){
            if(a[i-1]==1){
                if(i>=2&&a[i-2]==3) ans+=2;
                else ans+=3;
            }
            else {flag=1;break;}
        }
        else if(a[i]==1){
            if(a[i-1]==2)   ans+=3;
            else if(a[i-1]==3)  ans+=4;
            else {flag=1;break;}
        }
        else{
            if(a[i-1]==1)   ans+=4;
            else {flag=1;break;}
        }
    }
    if(flag)    cout<<"Infinite"<<endl;
    else {cout<<"Finite"<<endl;cout<<ans<<endl;}
    return 0;
}

B. Ugly Pairs

You are given a string, consisting of lowercase Latin letters.

A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string “abaca” contains ugly pairs at positions (1,2) — “ab” and (2,3) — “ba”. Letters ‘a’ and ‘z’ aren’t considered neighbouring in a alphabet.

Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can’t add any new letters or remove the existing ones. You can also leave the order the same.

If there are multiple answers, print any of them.

You also have to answer T separate queries.

Input
The first line contains a single integer T (1≤T≤100) — the number of queries.

Each of the next T lines contains string s (1≤|s|≤100) — the string for the next query. It is guaranteed that it contains only lowercase Latin letters.

Note that in hacks you have to set T=1.

Output
Print T lines. The i-th line should contain the answer to the i-th query.

If the answer for the i-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can’t add any new letters or remove the existing ones. You can also leave the order the same.

If there are multiple answers, print any of them.

Otherwise print “No answer” for that query.

Example
inputCopy
4
abcd
gg
codeforces
abaca
outputCopy
cadb
gg
codfoerces
No answer
Note
In the first example answer “bdac” is also correct.

The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.

There are lots of valid answers for the third example.

题意: 题意:给你一个串,将他们重新排列,使得相邻的字符在字母表中不是相邻的。
例:abcd->dbca
思路: 将字符从小到大排序,分奇数位偶数位字符,分别放在不同的串内,判断他们的首字符和未字符是否相等!!
我的编译器不能用back和front,而别的电脑的编译器就可以用,提交代码也A了,搞了半天…

#include<bits/stdc++.h>
using namespace std;

bool cmp(char c1,char c2)
{
    return c1<c2;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        sort(s.begin(),s.end(),cmp);
        string s1,s2;
        for(int i=0;i<s.size();i++){
            if((s[i]-'a')%2)   s2+=s[i];
            else s1+=s[i];
        }
        if(abs(s1.back()-s2.front())>1) cout<<s1<<s2<<endl;
        else if(abs(s1.front()-s2.back())>1) cout<<s2<<s1<<endl;
        else cout<<"No answer\n";
    }
    return 0;
}

C. Match Points

You are given a set of points x1, x2, …, xn on the number line.

Two points i and j can be matched with each other if the following conditions hold:

neither i nor j is matched with any other point;
|xi−xj|≥z.
What is the maximum number of pairs of points you can match with each other?

Input
The first line contains two integers n and z (2≤n≤2⋅105, 1≤z≤109) — the number of points and the constraint on the distance between matched points, respectively.

The second line contains n integers x1, x2, …, xn (1≤xi≤109).

Output
Print one integer — the maximum number of pairs of points you can match with each other.

Examples
inputCopy
4 2
1 3 3 7
outputCopy
2
inputCopy
5 5
10 9 5 8 7
outputCopy
1
Note
In the first example, you may match point 1 with point 2 (|3−1|≥2), and point 3 with point 4 (|7−3|≥2).

In the second example, you may match point 1 with point 3 (|5−10|≥5).

题意: 有n个数和z,使得唯一一对数|xi-xj|>=z。这样的数最多有多少?

思路: 由于唯一确定一对数,所以最多有n/2对数,所以可以将序列从小到大排序,分成左右两组a<b<c<d,若a c满足,则a d必然满足,同理,若b c满足,则b d必定满足

#include<bits/stdc++.h>
using namespace std;
int a[210000];
int main()
{
    int n,z;
    cin>>n>>z;
    for(int i=0;i<n;i++)    scanf("%d",&a[i]);
    sort(a,a+n);
    int ans=0,l=0,r=n/2;
    if(n%2) r++;
    while(l<r){
        if(a[r]-a[l]>=z){
            ans++;
            l++;
        }
        r++;
        if(r == n)  break;
    }
    cout<<ans<<endl;
    return 0;
}

"educational codeforces round 103 (rated for div. 2)"是一个Codeforces平台上的教育性比赛,专为2级选手设计评级。以下是有关该比赛的回答。 "educational codeforces round 103 (rated for div. 2)"是一场Codeforces平台上的教育性比赛。Codeforces是一个为程序员提供竞赛和评级的在线平台。这场比赛是专为2级选手设计的,这意味着它适合那些在算法和数据结构方面已经积累了一定经验的选手参与。 与其他Codeforces比赛一样,这场比赛将由多个问题组成,选手需要根据给定的问题描述和测试用例,编写程序来解决这些问题。比赛的时限通常有两到三个小时,选手需要在规定的时间内提交他们的解答。他们的程序将在Codeforces的在线评测系统上运行,并根据程序的正确性和效率进行评分。 该比赛被称为"educational",意味着比赛的目的是教育性的,而不是针对专业的竞争性。这种教育性比赛为选手提供了一个学习和提高他们编程技能的机会。即使选手没有在比赛中获得很高的排名,他们也可以从其他选手的解决方案中学习,并通过参与讨论获得更多的知识。 参加"educational codeforces round 103 (rated for div. 2)"对于2级选手来说是很有意义的。他们可以通过解决难度适中的问题来测试和巩固他们的算法和编程技巧。另外,这种比赛对于提高解决问题能力,锻炼思维和提高团队合作能力也是非常有帮助的。 总的来说,"educational codeforces round 103 (rated for div. 2)"是一场为2级选手设计的教育性比赛,旨在提高他们的编程技能和算法能力。参与这样的比赛可以为选手提供学习和进步的机会,同时也促进了编程社区的交流与合作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值