zoukankan      html  css  js  c++  java
  • 寒假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
  • 相关阅读:
    如何写好软件需求说明?
    怎么做,与为什么?[转]
    WCF学习中遇到的一些问题
    删除数据库中所有表、视图以及存储过程
    如何获取Repeater的当前行号
    Asp.Net 获取FileUpload控件的文件路径、文件名、扩展名
    IP地址通过WebService得到城市
    springboot、intellij与docker的结合
    开源GIS软件初探
    Statement接口提供的execute、executeQuery和executeUpdate之间的区别
  • 原文地址:https://www.cnblogs.com/awsent/p/4266989.html
Copyright © 2011-2022 走看看