"Codeforces 353 A" Domino

Source: Internet
Author: User

"Link" I am the link, point me:)
Test instructions

Exercises


Category discussion a wave
Sets the odd number of the first array to Cnt1
The odd number of the second array is Cnt2
Obviously only in the case of (Cnt1+cnt2)%2==0.
It is possible for the first array to be even, and the second array to be even.
(because odd numbers have to appear even several times to do so.)
So it's only possible that cnt1 and cnt2 are even, so output 0
Otherwise, cnt1 and Cnt2 are odd, see if there is a position I only a[i] or only b[i] is odd. Some words output 1.
Other cases are illegal.

Code

#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;}

"Codeforces 353 A" Domino

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.