At Coder 2302 Addition

http://www.elijahqi.win/archives/1360Time limit時間制限 : 2sec / Memory limitメモリ制限 : 256MB

配点 : 300 点

問題文
黒板に N 個の整数が書かれています。i 番目の整数は Ai です。

これらの数に対して、高橋君は以下の操作を繰り返します。

偶奇が等しい 2 つの数 Ai,Aj を一組選び、それらを黒板から消す。
その後、二つの数の和 Ai+Aj を黒板に書く。
最終的に黒板に数が 1 つだけ残るようにできるかどうか判定して下さい。

制約
2≦N≦105
1≦Ai≦109
Ai は整数
入力
入力は以下の形式で標準入力から与えられる。

N
A1 A2 … AN
出力
黒板に数 1 つだけ残るようにできるなら YES を、そうでないなら NO を出力せよ。

入力例 1
Copy
3
1 2 3
出力例 1
Copy
YES
以下のようにすれば、数を 1 つだけ残すことができます。

黒板から 1 と 3 を消し、4 を書く。このとき、残る数は (2,4) である。
黒板から 2 と 4 を消し、6 を書く。このとき、残る数は 6 だけである。
入力例 2
Copy
5
1 2 3 4 5
出力例 2
Copy
NO
Score : 300 points

Problem Statement
There are N integers written on a blackboard. The i-th integer is Ai.

Takahashi will repeatedly perform the following operation on these numbers:

Select a pair of integers, Ai and Aj, that have the same parity (that is, both are even or both are odd) and erase them.
Then, write a new integer on the blackboard that is equal to the sum of those integers, Ai+Aj.
Determine whether it is possible to have only one integer on the blackboard.

Constraints
2≦N≦105
1≦Ai≦109
Ai is an integer.
Input
The input is given from Standard Input in the following format:

N
A1 A2 … AN
Output
If it is possible to have only one integer on the blackboard, print YES. Otherwise, print NO.

Sample Input 1
Copy
3
1 2 3
Sample Output 1
Copy
YES
It is possible to have only one integer on the blackboard, as follows:

Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.
Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.
Sample Input 2
Copy
5
1 2 3 4 5
Sample Output 2
Copy
NO
统计%2余1的数有多少 如果奇数个 输出NO否则输出YES

#include<cstdio>
#define N 110000
inline char gc(){
    static char now[1<<16],*T,*S;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
inline int read(){
    int x=0;char ch=gc();
    while (ch<'0'||ch>'9') ch=gc();
    while (ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
    return x;
}
int n,a[N];
int main(){
    freopen("addition.in","r",stdin);
    n=read();
    for (int i=1;i<=n;++i) a[i]=read();int ans1=0;
    for (int i=1;i<=n;++i) if (a[i]%2) ans1++;
    if (ans1%2) printf("NO");else printf("YES");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值