Codeforces Round #436 A. Fair Game

时间:2022-08-29 23:02:30

题意:给你n张卡片,上面写有数字,两个人选择两个数字,把相同数字的卡片都拿走,问能不能拿走所有的卡片并且两个人拿的卡片书相同。

Examples
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

思路:水题啊,瞎搞搞记录一下就好了,看题太不仔细了,还以为每个人能拿多张卡片orz。

代码:
#include<iostream>
#include<string.h>
using namespace std;
int vis[110]; int main(){
    int n,x,sum1=0,sum2=0,c=1,k1,k2;
    bool f=1;
    memset(vis,0,sizeof(vis));
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        if(vis[x]==0){
            if(c==3){
                f=0;
                break;
            }
            else if(c==1)k1=x,vis[x]=c++;
            else if(c==2)k2=x,vis[x]=c++;
        }
        if(vis[x]==1)sum1++;
        else sum2++;
    }
    if(f&&c==3&&sum1==sum2){
        cout<<"YES"<<endl;
        cout<<k1<<' '<<k2<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;    
}