Educational Codeforces Round 64 (Rated for Div. 2)

题目链接:https://codeforces.com/contests/1156

A. Inscribed Figures

题目大意:假设1代表圆形,2代表正三角形,3代表正方形,那么如例一所示2 1 3就代表正三角形内接圆形,同时内接圆的内部再内接正方形。那么现在所需要求的就是通过不断内接图形最终有多少个交点,如果在这个过程中内接的图形与之有边重合则 Infinite

解题思路:分别画出1 2 3 、1 3 2、2 1 3、2 3 1、3 1 2、3 2 1,就可以得出规律如下

  • 1中内接2或者2中内接1,则有3个交点
  • 1中内接3或者3中内切1,则有4个交点
  • 2和3相连一定存在边重合的现象,所以2和3之间一定要有1,否则 Infinite
  • 特殊情况 3 1 2,存在重合点,需要特别判断

#include<cstdio>
#include<iostream>
using namespace std;
// zhicheng
// May,2,2019
int main()
{
    int n,ans=0,a[105];
    scanf("%d",&n);
    for(int i=0;i<n;++i)
    {
        scanf("%d",&a[i]);
        if(i==0||ans==-1) continue;
        if(a[i]*a[i-1]==6) ans=-1;
        else if(a[i]*a[i-1]==2) ans+=3;
        else if(a[i]*a[i-1]==3) ans+=4;
        if(i>=2&&a[i]==2&&a[i-2]==3) --ans;
    }
    ans==-1?printf("Infinite\n"):printf("Finite\n%d\n",ans);
    return 0;
}

B. Ugly Pairs

题目大意:给定由小写字母组成的字符串,现在规定按照26字母表中相邻的字母不能在字符串中的位置也相邻,需要对字符串中各个字符的位置重新,问重新排列后是否可以达到题目要求,如果可以的话,输出排列后的结果(结果不唯一),否则的话,输出“No answer“

解题思路:把字符串各个字母出现的次数存进num[26]数组中,然后根据num[26]将26字母表中偶数位的字母存进字符串s1中,再将26字母表中奇数位的字母存进字符串s2中,最后的组合有s1+s2或者s2+s1,而这样的组合一定满足题目要求

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
// zhicheng
// May,2,2019
int main()
{
    int _;
    char s[105],num[26];
    for(scanf("%d",&_);_;--_)
    {
        memset(num,0,sizeof(num));
        scanf("%s",s);
        for(int i=0;s[i];++i) ++num[s[i]-‘a‘];
        string s1,s2;
        for(int i=0;i<26;i+=2) while(num[i]--) s1+=‘a‘+i;
        for(int i=1;i<26;i+=2) while(num[i]--) s2+=‘a‘+i;
        if(abs(s1.back()-s2.front())>1) cout<<s1<<s2<<"\n";
        else if(abs(s1.front()-s2.back())>1) cout<<s2<<s1<<"\n";
        else cout<<"No answer\n";
    }
    return 0;
}

C. Match Points

题目大意:给定n个数,要求在这n个数中找到两两匹配的数,匹配的条件为

    • 已经参与匹配的数不可再次参与匹配
    • 两个匹配的数字差的绝对值不小于z

    问由n个数组成的序列中,最多可以组成多少对这样的匹配数

解题思路:先从小到大排序,再用尺选法进行匹配,时间复杂度为O(nlogn)

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
// zhicheng
// May,2,2019
const int maxn=2*1e5+10;
int a[maxn];

int main()
{
    int n,z,ans=0;scanf("%d %d",&n,&z);
    for(int i=0;i<n;++i) scanf("%d",&a[i]);
    sort(a,a+n);
    int p=n/2;
    for(int i=0;i<n/2;++i)
    {
        for(;p<n;++p)
        {
            if(a[p]-a[i]>=z){++ans;++p;break;}
        }
    }
    printf("%d\n",ans);
    return 0;
}

D. 0-1-Tree

E. Special Segments of Permutation

F. Card Bag

G. Optimizer

原文地址:https://www.cnblogs.com/emerson027/p/10801458.html

时间: 2024-10-17 07:31:41

Educational Codeforces Round 64 (Rated for Div. 2)的相关文章

Educational Codeforces Round 64 (Rated for Div. 2) (线段树二分)

题目:http://codeforces.com/contest/1156/problem/E 题意:给你1-n  n个数,然后求有多少个区间[l,r] 满足    a[l]+a[r]=max([l,r]) 思路:首先我们去枚举区间肯定不现实,我们只能取把能用的区间去用,我们可以想下每个数当最大值的时候所做的贡献 我们既然要保证这个数为区间里的最大值,我们就要从两边扩展,找到左右边界能扩展在哪里,这里你直接去枚举肯定不行 这里我们使用了线段树二分去枚举左右区间最远能走到哪里,然后很暴力的去枚举短

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm

Educational Codeforces Round 57 (Rated for Div. 2)

get人生第二场CF! 成绩:(exACM) rank858 AC3/7 Penalty57 rating1648(+52) 题目:Educational Codeforces Round 57 (Rated for Div. 2) 错题题解: D. Easy Problem E. The Top Scorer F. Inversion Expectation G. Lucky Tickets 原文地址:https://www.cnblogs.com/xht37/p/10198321.html

Educational Codeforces Round 58 (Rated for Div. 2)(待更新)

get人生第七场CF! 成绩:(exACM) rank AC3/7 Penalty104 rating() 题目:Educational Codeforces Round 58 (Rated for Div. 2) 错题题解: C. Division and Union 原文地址:https://www.cnblogs.com/xht37/p/10260260.html