Educational Codeforces Round 27

来源:互联网 发布:淘宝商品销量查询工具 编辑:程序博客网 时间:2024/06/07 22:51

A. Chess Tourney
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 regardless of 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".

Examples
input
21 3 2 4
output
YES
input
13 3
output
NO

题意:

给你几个棋手和对应的实力。让你分成2队,1队的所有人都能打败2队的所有人。

POINT:

排序,比较1队的尾巴和2队的头。


#include <iostream>#include <string.h>#include <vector>#include <algorithm>#include <math.h>#include <stdio.h>using namespace std;#define  LL long longint main(){    int n;    while(~scanf("%d",&n))    {        int a[222];        for(int i=1;i<=2*n;i++)        {            scanf("%d",&a[i]);        }        sort(a+1,a+1+2*n);        if(a[n]<a[n+1])        {            printf("YES\n");        }        else printf("NO\n");    }}



B. Luba And The Ticket
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
input
000000
output
0
input
123456
output
2
input
111000
output
1
Note

In the first example the ticket is already lucky, so the answer is 0.

In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.

In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.


题意:

给你6个数字,前3个一组,后3个一组,让你改变最少的数字,使他们的数字和相等。可以任意变0-9.

point:

要不就是大的一组减小,要不小的一组增大。先分好。小的一组都9-a[i],代表可以增加的数量。

然后每次让差值减小,贪心减。

赛中做的总是只变化一组,被hack了。

#include <iostream>#include <string.h>#include <vector>#include <algorithm>#include <math.h>#include <stdio.h>using namespace std;#define  LL long longint main(){    char s[7];    scanf("%s",s);    int a[6];    for(int i=0;i<6;i++)        a[i]=s[i]-'0';    int sum1=a[0]+a[1]+a[2];    int sum2=a[3]+a[4]+a[5];    if(sum2==sum1){        printf("0\n");        return 0;    }    if(sum2>sum1)    {        swap(a[0],a[3]);        swap(a[1],a[4]);        swap(a[2],a[5]);        swap(sum2,sum1);    }    a[3]=9-a[3];    a[4]=9-a[4];    a[5]=9-a[5];    int aim=sum1-sum2;    sort(a,a+6);    int now=0;    int p=0;    for(int i=5;i>=0;i--)    {        now+=a[i];        p++;        if(aim<=now)            break;    }    printf("%d\n",p);        }



C. Two TVs
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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).

Examples
input
31 22 34 5
output
YES
input
41 22 32 31 2
output
NO


题意:

HDU的今年暑假不AC。

注意节目可以从0开始。wa了一次。

#include <iostream>#include <string.h>#include <vector>#include <algorithm>#include <math.h>#include <stdio.h>using namespace std;#define  LL long longstruct node{    int b,e;}a[2*100000+6];bool cmd(node a ,node b){    if(a.b!=b.b)    {        return a.b<b.b;    }    else        return a.e<b.e;}int main(){    int n;    scanf("%d",&n);    for(int i=1;i<=n;i++)    {        scanf("%d %d",&a[i].b,&a[i].e);    }    sort(a+1,a+1+n,cmd);    int t1=-1,t2=-1;    int flag=0;    for(int i=1;i<=n;i++)    {        if(t1<a[i].b)        {            t1=a[i].e;            continue;        }        else if(t2<a[i].b)        {            t2=a[i].e;        }        else        {            flag=1;            break;        }    }    if(flag) printf("NO\n");    else printf("YES\n");}








原创粉丝点击