codeforces --- Round #248 (Div. 2) A. Kitahara Haruki's Gift

A. Kitahara Haruki's Gift
 

Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.

Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.

But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.

Output

In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).

Sample test(s)
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note

In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.

 

【题目大意】

有两种面值的钞票,100元或200元的各有若干张,现在要将其分给两个人,要你判断能否均分。

 

【题目分析】

既然判断能否均分,那就来做分类讨论:

 

伪代码如下:

 

if(200元的能均分)

{

     if(100元的也能均分)

              输出YES;

     else   输出NO;

}

else

{

       if(100元的数量<2)

                输出NO;

       else

             {

                        100元的数量-=2;//(为了将200元的凑成2的倍数,当然也可不减)

                         if(100元的数量能均分)

                                  输出YES;

                           else  输出NO;

              }

}

结束;

 

 

AC代码1:

复制代码
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int i,a;
    int cnt1=0,cnt2=0;
    for(i=0;i<n;i++)
    {
        cin>>a;
        if(a==100)
            cnt1++;
        else cnt2++;
    }
    if(cnt2%2==0)
    {
        if(cnt1%2==0)
            cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    else
    {
        if(cnt1<2)
            cout<<"NO"<<endl;
        else
        {
            cnt1-=2;
            if(cnt1%2==0)
               cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
    }
    return 0;
}
复制代码

 

 

ac代码2:

复制代码
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int i,a;
    int cnt1=0,cnt2=0;
    for(i=0;i<n;i++)
    {
        cin>>a;
        if(a==100)
            cnt1++;
        else cnt2++;
    }
    if(cnt2%2==0)
    {
        if(cnt1%2==0)
            cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    else
    {
        if(cnt1<2)
            cout<<"NO"<<endl;
        else
        {
            if(cnt1%2==0)
               cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
    }
    return 0;
}
复制代码

 

 

 

ac代码3:

 

复制代码
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;

long n,a,h,t,i;

int main()
{
    while(~scanf("%ld",&n))
    {
        h=t=0;
        for(i=0;i<n;i++)
        {
            scanf("%ld",&a);
            if(a==100)
                h++;
            else
                t++;
        }
        t=t%2;
        h-=t*2;
        if(h<0 || h%2==1)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}
复制代码

 

 

ac代码4:

复制代码
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    int t;
    cin >> t;
    int a=0;
    int b=0;
    int e;
    for (int i=0;i<t;i++)
    {
        cin >> e;
        if (e==200)a++;
        else b++;
    }
    int c=0,d=0;
    while (a>0)
    {
        if (c<d)
        {
            c+=200;
        }
        else
        {
            d+=200;
        }
        a--;
    }
    while(b>0)
    {
        if (c<d)
        {
            c+=100;
        }
        else
        {
            d+=100;
        }
        b--;
    }
    if (c==d)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}
复制代码

 

 

 

 

posted @   北岛知寒  阅读(366)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示
主题色彩