zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 27 A B C

    A. Chess Tourney
     

    Berland annual chess tournament is coming!

    Organizers have gathered n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.

    Thus, organizers should divide all n players into two teams with n people each in such a way that the first team always wins.

    Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win.

    After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random.

    Is it possible to divide all n players into two teams with n people each so that the player from the first team in every pair wins regardlessof the results of the drawing?

    Input

    The first line contains one integer n (1 ≤ n ≤ 100).

    The second line contains n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).

    Output

    If it's possible to divide all n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".

    题意 给你2*n个数  让你选择n个数  然后 必须使得 选的n个数  比没选的n个数里面的数都要大

    就很基本 sort一下  比较一下1-n 中最大的  和 n+1 到2*n中最小的 是否相等

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    
    int s[220];
    int main ()
    {
        int n;
        cin>>n;
        for(int i=1;i<=2*n;i++)
            cin>>s[i];
        sort(s+1,s+2*n+1);
        if(s[n]==s[n+1])
            puts("NO");
        else
            puts("YES");
    }
    B. Luba And The Ticket
     

    Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.

    The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.

    Input

    You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.

    Output

    Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.

     
    题意 给你6个数字 问你使得 前三个和 和后面三个和 相等的 数字改动的最少数量
     
    大概我是分情况讨论的   下面就是我AC的代码  把 0 ,1 ,2 的情况都讨论了   结果 当然是GG的了,并且写的时候脑子时刻会短路 不知道会x - 0 还是9 - x
    大概是我数学逻辑不好的吧
     
    #include<bits/stdc++.h>
    using namespace std;
    
    char a[5],b[5];
    
    int main ()
    {
        for(int i=0;i<3;i++)
            cin>>a[i];
        for(int i=0;i<3;i++)
            cin>>b[i];
        sort(a,a+3);sort(b,b+3);
    
        int s1=0,s2=0;
        for(int i=0;i<3;i++)
            s1+=a[i],s2+=b[i];
        if(s1 == s2)//0的情况
        {
            puts("0");
            return 0;
        }
        if(s1 > s2)//1的情况
        {
            int mx = max('9'-b[0],a[2]-'0');
            //cout << '9'-b[0]<<endl;
            //cout<<a[0]-'0'<<endl;
            if(s1 - s2 <= mx)
            {
                puts("1");
                return 0;
            }
        }
        if(s2 > s1)
        {
            int mx = max('9'-a[0],b[2]-'0');
            if(s2 - s1 <= mx)
            {
                puts("1");
                return 0;
            }
        }
        if(s1 < s2)
        {
            int mx = max('9'-a[0] + b[2]-'0',max('9'-a[0]+'9'-a[1],b[2]-'0'+b[1]-'0'));
    
            if(s2-s1 <= mx)
            {
                puts("2");
                return 0;
            }
        }
        if(s2 < s1)
        {
            int mx = max('9'-b[0] + a[2]-'0',max('9'-b[0]+'9'-b[1],a[2]+a[1]-'0'-'0'));
            if(s1-s2 <= mx)
            {
                puts("2");
                return 0;
            }
        }
        puts("3");
    }
    下面是看到别人的blog后 写出来的  感觉自己是真的菜
    //都是知识盲区 抓紧补
    #include<bits/stdc++.h>
    using namespace std;
    char s[10];
    int num[10];
    
    bool cmp(int a,int b)
    {
        return a>b;
    }
    int main ()
    {
        int s1 =0,s2 = 0;
        cin>>s;
        for(int i=0;i<3;i++)
            s1+= s[i] -'0';
        for(int i=3;i<6;i++)
            s2+= s[i] -'0';
        if(s1 == s2)
        {
            puts("0");
            return 0;
        }
        if(s1 > s2)  //前面数字大 大的要尽量变0  小的尽量变9
        {
            for(int i=0;i<3;i++)
                num[i] = s[i]-'0' - 0;
            for(int i=3;i<6;i++)
                num[i] = 9- (s[i]-'0');
            sort(num,num+6,cmp);
            for(int i=1;i<6;i++)
                num[i] += num[i-1];
            for(int i=0;i<6;i++)
            {
                if(num[i] >= s1-s2)
                {
                    cout << i+1<<endl;
                    return 0;
                }
            }
        }
        if(s2 > s1)
        {
            for(int i=0;i<3;i++)
                num[i] = 9-(s[i]-'0');
            for(int i=3;i<6;i++)
                num[i] = (s[i]-'0')-0;
            sort(num,num+6,cmp);
            for(int i=1;i<6;i++)
                num[i] += num[i-1];
    
            for(int i=0;i<6;i++)
            {
                if(num[i] >= s2-s1)
                {
                    cout << i+1<<endl;
                    return 0;
                }
            }
        }
    }
     
    C. Two TVs
     

    Polycarp is a great fan of television.

    He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment li and ends at moment ri.

    Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV.

    Polycarp wants to check out all n shows. Are two TVs enough to do so?

    Input

    The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of shows.

    Each of the next n lines contains two integers li and ri (0 ≤ li < ri ≤ 109) — starting and ending time of i-th show.

    Output

    If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).

    题意:题目大概能看懂的吧    一个小trick 就是 一个结束和一个开始的时间重合的话,是不可以使用相同的电视的

    //感觉像是模拟
    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 2e5+10;
    int n;
    struct node
    {
        int l,r;
        bool operator<(const node& a)const
        {
            return l < a.l;
        }
    }s[maxn];
    priority_queue<int,vector<int>,greater<int> >s1,s2;
    
    int main ()
    {
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>s[i].l >> s[i].r;
        sort(s+1,s+n+1);
    
        for(int i=1;i<=n;i++)
        {
            if(s1.empty())
            {
                s1.push(s[i].r);
                continue;
            }
            if(s2.empty())
            {
                s2.push(s[i].r);
                continue;
            }
            int now1 = s1.top();
            if(now1 < s[i].l)
            {
                s1.pop();
                s1.push(s[i].r);
                continue;
            }
            int now2 = s2.top();
            if(now2 < s[i].l)
            {
                s2.pop();
                s2.push(s[i].r);
                continue;
            }
            puts("NO");return 0;
        }
        puts("YES");
    }
  • 相关阅读:
    【Win 10 应用开发】在后台播放视频
    【Win 10 应用开发】UI Composition 札记(八):用 XamlLight 制作灯光效果
    【Win 10 应用开发】UI Composition 札记(七):基于表达式的动画
    【Win 10 应用开发】UI Composition 札记(六):动画
    Redis中的Scan命令的使用
    MySQL8.0新特性
    IP白名单的实现(PHP)
    mysql分组后获取每个组排序后的第一条数据(整行)
    PHP 之sha256 sha512封装
    Mysql数据库中CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP区别
  • 原文地址:https://www.cnblogs.com/Draymonder/p/7410723.html
Copyright © 2011-2022 走看看