2018暑假最后一次团队赛

版权声明:转载时 别忘了注明出处 https://blog.csdn.net/ZCY19990813/article/details/82389991

You are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be of them.

You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis.

Find the minimal number of layers you have to use for the given N.

Input

The only input line contains a single integer N (1 ≤ N ≤ 100).

Output

Output a single integer - the minimal number of layers required to draw the segments for the given N.

Sample Input

Input

2

Output

2

Input

3

Output

4

Input

4

Output

6

Hint

As an example, here are the segments and their optimal arrangement into layers for N = 4.

题意:只允许落下来 问最少存在几层

思路:转化成会场问题

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long  ll;
const double pi=acos(-1.0);
const double e=exp(1);
const int N = 210000;
int t;
struct p
{
    int a;
    int b;
    int no;
}x[100010];
int cmp(struct p a,struct p b)
{
    if(a.a!=b.a)
        return a.a<b.a;
    else
        return a.b<b.b;

}

int main()
{
    int n,i,j;
    scanf("%d",&n);
    t=n*(n+1)/2;
    memset(x,0,sizeof(x));
    for(i=0;i<=n-1;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            x[t].a=i;
            x[t++].b=j;
        }
    }
    sort(x,x+n,cmp);
    int sum=1;
    x[0].no=sum;
    for(i=1;i<=t-1;i++)
    {
        for(j=0;j<i;j++)
        {
            if(x[j].no!=0&&x[j].b==x[i].a)
            {
                x[i].no=x[j].no;
                x[j].no=0;
                break;
            }
        }
        if(j==i)
        {
            sum+=1;
            x[i].no=sum;
        }
    }
    printf("%d\n",sum);



}

Pig is visiting a friend.

Pig's house is located at point 0, and his friend's house is located at point m on an axis.

Pig can use teleports to move along the axis.

To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.

Formally, a teleport located at point x with limit y can move Pig from point x to any point within the segment [x; y], including the bounds.

Determine if Pig can visit the friend using teleports only, or he should use his car.

Input

The first line contains two integers n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of teleports and the location of the friend's house.

The next n lines contain information about teleports.

The i-th of these lines contains two integers ai and bi (0 ≤ ai ≤ bi ≤ m), where ai is the location of the i-th teleport, and bi is its limit.

It is guaranteed that ai ≥ ai - 1 for every i (2 ≤ i ≤ n).

Output

Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.

You can print each letter in arbitrary case (upper or lower).

Sample Input

Input

3 5
0 2
2 4
3 5

Output

YES

Input

3 7
0 4
2 5
6 7

Output

NO

Hint

The first example is shown on the picture below:

Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.

The second example is shown on the picture below:

You can see that there is no path from Pig's house to his friend's house that uses only teleports.

题意:他可以在任意处下车 问可以从起点到终点吗  其实就是判断不能有空的

思路:染色

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long  ll;
const double pi=acos(-1.0);
const double e=exp(1);
const int N = 210000;
int main()
{
    int m,n,flag[1010]={0},a,b,i;
    scanf("%d%d",&m,&n);
    while(m--)
    {
        scanf("%d%d",&a,&b);
        for(i=a+1;i<=b;i++)
            flag[i]++;
    }
    for(i=1;i<=n;i++)
    {
        if(flag[i]==0)
            break;
    }
    if(i>n)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.

Input

The first line contains a single positive integer n (2 ≤ n ≤ 105).

The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.

Output

Print "Yes" if there is such a point, "No" — otherwise.

You can print every letter in any case (upper or lower).

Sample Input

Input

3
1 1
-1 -1
2 -1

Output

Yes

Input

4
1 1
2 2
-1 1
-2 2

Output

No

Input

3
1 2
2 1
4 60

Output

Yes

Hint

In the first example the second point can be removed.

In the second example there is no suitable for the condition point.

In the third example any point can be removed.

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long  ll;
const double pi=acos(-1.0);
const double e=exp(1);
const int N = 210000;


int main()
{
   int a,b,c,x=0,y=0,i;
   scanf("%d",&a);
   for(i=0;i<a;i++)
   {
       scanf("%d%d",&b,&c);
       if(b<0)
        x++;
       else
        y++;
   }
   if(x==1||y==1||(x==0&&y!=0)||(y==0&&x!=0))
        printf("Yes\n");
   else
        printf("No\n");
}

You have a fraction . You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.

Input

The first contains three single positive integers a, b, c (1 ≤ a < b ≤ 105, 0 ≤ c ≤ 9).

Output

Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.

Sample Input

Input

1 2 0

Output

2

Input

2 3 7

Output

-1

Hint

The fraction in the first example has the following decimal notation: . The first zero stands on second position.

The fraction in the second example has the following decimal notation: . There is no digit 7 in decimal notation of the fraction.

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long  ll;
const double pi=acos(-1.0);
const double e=exp(1);
const int N = 210000;


int main()
{
   int a,b,c,x,y,i;
   scanf("%d%d%d",&a,&b,&c);
    for(i=0;i<1000;i++)
    {
        a*=10;
        y=a/b;
        if(y==c)
            break;
        a=a%b;
    }
    if(i<1000)
        printf("%d\n",i+1);
    else
        printf("-1\n");
}

Petya and Vasya decided to play a game. They have n cards (n is an even number). A single integer is written on each card.

Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written.

The game is considered fair if Petya and Vasya can take all n cards, and the number of cards each player gets is the same.

Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair.

Input

The first line contains a single integer n (2 ≤ n ≤ 100) — number of cards. It is guaranteed that n is an even number.

The following n lines contain a sequence of integers a1, a2, ..., an (one integer per line, 1 ≤ ai ≤ 100) — numbers written on the n cards.

Output

If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.

In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them.

Sample Input

Input

4
11
27
27
11

Output

YES
11 27

Input

2
6
6

Output

NO

Input

6
10
20
30
20
10
20

Output

NO

Input

6
1
1
2
2
3
3

Output

NO

Hint

In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.

In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct.

In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards.

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long  ll;
const double pi=acos(-1.0);
const double e=exp(1);
const int N = 210000;
int main()
{
    int n,a[110],b[110],c[100]={0},l=0,i;
    memset(b,0,sizeof(b));
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        b[a[i]]++;
    }
    for(i=0;i<=100;i++)
    {
        if(b[i]>0)
        {
            c[l++]=i;
        }
    }
    if(l>2||l<2)
        printf("NO\n");
    else
    {
        if(b[c[0]]==b[c[1]])
            printf("YES\n%d %d\n",c[0],c[1]);
        else
            printf("NO\n");
    }

    return 0;
}

Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.

Let A be a set of positions in the string. Let's call it pretty if following conditions are met:

  • letters on positions from A in the string are all distinct and lowercase;
  • there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).

Write a program that will determine the maximum number of elements in a pretty set of positions.

Input

The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.

The second line contains a string s consisting of lowercase and uppercase Latin letters.

Output

Print maximum number of elements in pretty set of positions for string s.

Sample Input

Input

11
aaaaBaabAbA

Output

2

Input

12
zACaAbbaazzC

Output

3

Input

3
ABC

Output

0

Hint

In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.

In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.

In the third example the given string s does not contain any lowercase letters, so the answer is 0.

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long  ll;
const double pi=acos(-1.0);
const double e=exp(1);
const int N = 210000;
int main()
{int t=100;


    int n,i,j=0,maxx=0,x,c[10010],s=0;
    char a[10010];
    memset(c,0,sizeof(c));
    scanf("%d",&n);
    scanf(" %s",a);

    for(i=0; i<n; i++)
    {
        if((a[i]>='A'&&a[i]<='Z')||i==(n-1))
        {
            if(i==(n-1)&&a[n-1]>='a'&&a[n-1]<='z'&&c[a[n-1]]==0)
                s++;
            if(s>maxx)
                maxx=s;
            s=0;
            memset(c,0,sizeof(c));
        }
        else
        {
            if(c[a[i]]==0)
            {
                s++;
                c[a[i]]++;
            }
            else
                c[a[i]]++;
        }

    }
    printf("%d\n",maxx);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ZCY19990813/article/details/82389991