8月11号团队赛水题走一波

1. Fair Game

Description

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(拿走全是5的牌) 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 then 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.

 

题目意思:给你n张牌,问是不是两种牌,并且数量相等。是的话还要输出两种牌。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<map>
 5 using namespace std;
 6 map<int,int>mp;
 7 map<int,int>::iterator it;
 8 int main()
 9 {
10     int n,a,i;
11     scanf("%d",&n);
12     for(i=0;i<n;i++)
13     {
14         scanf("%d",&a);
15         mp[a]++;
16     }
17     if(mp.size()==2&&mp[a]==n/2)
18     {
19         printf("YES\n");
20         for(it=mp.begin();it!=mp.end();it++)
21         {
22             printf("%d ",it->first);
23         }
24     }
25     else
26     {
27         printf("NO\n");
28     }
29     return 0;
30 }

 

2.Hungry Student Problem

Description

Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.

CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.

Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.

Help Ivan to answer this question for several values of x!

Input

The first line contains one integer n (1 ≤ n ≤ 100) — the number of testcases.

The i-th of the following n lines contains one integer xi (1 ≤ xi ≤ 100) — the number of chicken chunks Ivan wants to eat.

Output

Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.

Sample Input

Input
2
6
5
Output
YES
NO

Hint

In the first example Ivan can buy two small portions.

In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.

题目意思:判断一个数是否只能由3或者7组成。

解题思路:可以暴力一下也就100的数据量。

 

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int n,x;
 6     bool flag;
 7     cin>>n;
 8     while(n--)
 9     {
10         flag=0;
11         cin>>x;
12         for(int i=0; i<=100; i++)
13             for(int j=0; j<=100; j++)
14             {
15                 if(x==i*3+j*7)
16                 {
17                     flag=1;
18                     break;
19                 }
20             }
21         if(flag)
22             puts("YES");
23         else
24             puts("NO");
25     }
26     return 0;
27 }

 

不过这道题是有着一些规律的,只用3和7能够构成任何一个大于等于12的数!!!

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<string>
 4 #include<cstring>
 5 #include<cmath>
 6 using namespace std;
 7 
 8 int main()
 9 {
10     int t;
11     int n;
12     scanf("%d", &t);
13     while (t--)
14     {
15         scanf("%d", &n);
16         if (n % 3 == 0 || n % 7 == 0 || n == 10 || n > 12)
17         {
18             printf("YES\n");
19         }
20         else
21         {
22             printf("NO\n");
23         }
24     }
25     return 0;
26 }

 

 

 

3. Find Extra One

 

Description

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.

 

题目意思:能否存在这样一个点,删除该点之后,剩余的所有点都在y轴的同一侧。

解题思路:主要是判断在数据中在y轴两侧的个数,如果x>0和x<0的个数都大于1,那么肯定是不可能存在的。

 

 1 #include<cstdio>
 2 #include<cstring>
 3 int main()
 4 {
 5    int n,a,b,counts1,counts2,i;
 6    counts1=0;
 7    counts2=0;
 8    scanf("%d",&n);
 9    for(i=0;i<n;i++)
10    {
11        scanf("%d%d",&a,&b);
12        if(a<0)
13        {
14            counts1++;
15        }
16        else
17        {
18            counts2++;
19        }
20    }
21    if(counts1>1&&counts2>1)
22    {
23        printf("No\n");
24    }
25    else
26    {
27        printf("Yes\n");
28    }
29    return 0;
30 }

 

 

 

 

 

 

posted @ 2018-08-12 21:28  王陸  阅读(194)  评论(0编辑  收藏  举报