zoukankan      html  css  js  c++  java
  • 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
    ");
            else
                printf("YES
    ");
        }
        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;
    }
  • 相关阅读:
    c# 网络编程
    .net基础------抽象类和接口区别
    自己开发插件-------- 待续...........
    js 学习笔记 (this ,扩展方法,匿名函数)
    meta
    微信公众号支付接口-JSAPI
    跨境电商-311xml报文生成 更新到2018-10
    MooTools 异步请求验证
    微信JS-SDK 接口调用与 php 遇到的坑
    php 与 jquery中$.post()与attr()方法的简单实例 amaze modal 模态窗口
  • 原文地址:https://www.cnblogs.com/crazyacking/p/3749775.html
Copyright © 2011-2022 走看看