1. 程式人生 > >Codeforces Round #436 A. Fair Game

Codeforces Round #436 A. Fair Game

set string ems 題意 include 代碼 example return round

題意:給你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