• Educational Codeforces Round 76 (Rated for Div. 2)


    Educational Codeforces Round 76 (Rated for Div. 2)

    A: Two Rival Students

    水题,找距离最远,特判已经到达端点情况即可

    B: Magic Stick

    分析

    ​ 最开始想是暴力覆盖整个区间,但1e9很显然不可能,分析样例,盲猜只有以下情况是NO

    ((a==2 || a==3) && b!=3 && b!=2 && b!=1)
    (a==1 && b!=1)
    

    事实证明是正确的,因为操作中有-1这种微调操作,基本除了小数据会是no其他都是yes

    代码
    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        //freopen("test.in","r",stdin);
        //freopen("test.out","w",stdout);
        int T,b,a;
        cin>>T;
        while(T--){
            scanf("%d %d",&a,&b);
            if(a==1 && b!=1){printf("NO
    ");continue;}
            else if((a==2 || a==3) && b!=3 && b!=2 && b!=1){printf("NO
    ");continue;}
            else {printf("YES
    ");continue;}
        }
        return 0;
    }
    
    
    
    
    总结 :观察

    C: Dominated Subarray

    题意:

    找到所给串中最近的两个相同字母的距离

    思考:

    转化为结构体记录下原来的位置,按数值大小排序,同样的数字会出现在一起。(o(n))枚举位置差即可。

    代码
    #include <bits/stdc++.h>
    using namespace std;
    
    struct node{
        int x;
        int y;
        //char name;
    }a[200009];
    
    bool cmp(node a,node b){
        if (a.x < b.x )return true;
        else if ( a.x == b.x  ){
                if (a.y < b.y )return true ;
            }
        return false ;
    }
    
    int main(){
        //freopen("test.in","r",stdin);
        //freopen("test.out","w",stdout);
        int T,n;
        cin>>T;
        while(T--){
            cin>>n;
            for(int i=0;i<n;i++){scanf("%d",&a[i].x);a[i].y=i;}
            sort(a,a+n,cmp);
            //for(int i=0;i<n;i++)cout<<a[i].x<<" "<<a[i].y<<endl;//<<" "<<a[i].name
            int f=0,mn=2147483647;
    
            for(int i=0;i<n-1;i++){
                if(a[i].x==a[i+1].x){
                    f=1;
                    if(abs(a[i].y-a[i+1].y)+1<mn)mn=abs(a[i].y-a[i+1].y)+1;
                }
            }
            if(f==0)printf("-1
    ");
            else printf("%d
    ",mn);
        }
        return 0;
    }
    
    
    
    

    D: Yet Another Monster Killing Problem

    代码
    
    

    E: The Contest

    F: Make Them Similar

    
    
    本场总结:

    教育场果然被教育了qaq

  • 相关阅读:
    Delphi 获取时间的年月日
    Tlist删除技巧
    SQL Server 2008 允许远程连接的配置
    initialization & finalization
    display属性(元素转换)
    float 浮动
    盒模型
    行内元素和块级元素水平及垂直居中
    html常用的几个标签
    html基础
  • 原文地址:https://www.cnblogs.com/dpsama/p/11870096.html
Copyright © 2020-2023  润新知