码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #436 A. Fair Game

时间:2017-10-07 16:30:15      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:str   turn   思路   并且   put   space   ems   相同   cin   

题意:给你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;    
}

Codeforces Round #436 A. Fair Game

标签:str   turn   思路   并且   put   space   ems   相同   cin   

原文地址:http://www.cnblogs.com/ljy08163268/p/7634626.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!