【CodeForces 353 A】Domino

【链接】 我是链接,点我呀:)
【题意】

【题解】

分类讨论一波 设第一个数组的奇数个数为cnt1 第二个数组的奇数个数为cnt2 显然只有在(cnt1+cnt2)%2==0的情况下。 才可能第一个数组的和为偶数,第二个数组的和也为偶数 (因为奇数都要出现偶数次才可以。 所以只可能cnt1和cnt2都是偶数,那么输出0 否则,cnt1和cnt2都是奇数,看看有没有一个位置i只有a[i]或只有b[i]是奇数。有的话输出1. 其他情况都非法。

【代码】

#include <bits/stdc++.h>

using namespace std;

const int N = 1e2;

int n;
int x[N+10],y[N+10],cnt1,cnt2;

int main()
{
    #ifdef LOCAL_DEFINE
        freopen("rush.txt","r",stdin);
    #endif // LOCAL_DEFINE
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    for (int i = 1;i <= n;i++){
        cin >> x[i] >> y[i];
        if (x[i]&1) cnt1++;
        if (y[i]&1) cnt2++;
     }
     if (cnt1%2==0 && cnt2%2==0){
        cout<<0<<endl;
     }else if ( (cnt1+cnt2)%2 != 0){
        cout<<-1<<endl;
     }else{
        //cnt1+cnt2 == not odd
        for (int i = 1;i <= n;i++){
            if (x[i]&1 && y[i]%2==0)
                return cout<<1<<endl,0;
            if (x[i]%2==0 && y[i]&1)
                return cout<<1<<endl,0;
        }
        cout<<-1<<endl;
     }

    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/9739065.html