• 寒假CF1 小呀小苹果儿


    ///分苹果给两个人 判断是否能够平分 苹果不能切,存在200g和100g的苹果

    我每次想这种题目都会绕很远 so sad cf上的题目果然每次都让我很暴躁啊

    Description

    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 Input

    Input

    3

    100 200 100

    Output

    YES

    Input

    4

    100 100 100 200

    Output

    NO

    Hint

    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.

     1 #include<stdio.h>
     2 
     3 int main()
     4 
     5 {
     6 
     7 int n,i,a[100];
     8 
     9 while(~scanf("%d",&n))
    10 
    11 {
    12 
    13 int ans=0;
    14 
    15 int temp;
    16 
    17 for(i=0;i<n;i++)
    18 
    19 {
    20 
    21 scanf("%d",&a[i]);
    22 
    23 if(a[i]==200)
    24 
    25 ans++;
    26 
    27 }
    28 
    29 temp=n-ans;
    30 
    31 if(temp==0&&ans%2!=0)
    32 
    33 puts("NO");
    34 
    35 else if(temp%2==0&&n!=1)
    36 
    37 puts("YES");
    38 
    39 else
    40 
    41 puts("NO");
    42 
    43 }
    44 
    45 return 0;
    46 
    47 }
    View Code
  • 相关阅读:
    MySQL分页实现
    一周自学动态站点设计
    hdu 1233(还是畅通project)(prime算法,克鲁斯卡尔算法)(并查集,最小生成树)
    windows下使用lighttpd+php(fastcgi)+mysql
    Thinkpad E431 解决无线网卡无法开启
    创建与删除索引
    IC芯片
    Linux IPC(Inter-Process Communication,进程间通信)之管道学习
    POJ 3090 Visible Lattice Points 欧拉函数
    多区域显示(3)
  • 原文地址:https://www.cnblogs.com/awsent/p/4266989.html
Copyright © 2020-2023  润新知