acmore 1510: ZZ love Cookies

來源:互聯網
上載者:User

1510: ZZ love Cookies

Time Limit: 1 Sec  Memory Limit:
64 MB
Submit: 228  Solved: 139SubmitStatusWeb Board

Description

  One day, ZZ came to visit her friend LL and DD and saw that they have many cookies. The cookies are distributed into bags, As there are many cookies, ZZ decided that it’s no big deal
if she steals a bag. However, she doesn’t want to her friends to quarrel because of nothing when they divide the cookies. That’s why ZZ wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that LL and
DD could evenly divide into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookies bag so that the total number of cookies in the remaining bags was even?

Input

The first line contains the only integer n (1 ≤ n ≤ 1000) — the number of cookie bags Anna and Maria have. The second line contains n integers ai (1 ≤ ai ≤ 1000) — the number of cookies
in the i-th bag.

Output

Print in the only line the only number — the sought number of ways. If there are no such ways print 0.

Sample Input11101 2 2 3 4 4 4 2 2 2Sample Output18HINTSource

2013ACM多校聯合(4)_NUN

解題思路:只要留下的餅乾總數為偶數即可,若餅乾總數為偶數,則可取走餅乾數為偶數的任一包裹,否則可取走餅乾數為奇數的任一包裹。

#include<stdio.h>int main(){    int sum,sum1,sum2;    int n;    int a[1002];    int i;    while(scanf("%d",&n)!=EOF)    {        sum=0;        sum1=0;        sum2=0;        int j=n;        for(i=0;i<n;i++)        {            scanf("%d",&a[i]);            sum+=a[i];      //統計總數            if(a[i]%2==0)   //統計餅乾為偶數個的包裹個數                sum1++;            else        //統計餅乾為奇數個的包裹個數                sum2++;        }        if(sum%2==0)    //若總數為偶數,則可取走餅乾數為偶數的任意包裹            sum=sum1;        else                //若總數為奇數,則可取走餅乾數為奇數的任意包裹            sum=sum2;        printf("%d\n",sum);    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.