zoukankan      html  css  js  c++  java
  • Codeforces 129A-Cookies(暴力)

    A. Cookies
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie 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 ≤ 100) — the number of cookie bags Anna and Maria have. The second line contains nintegers ai (1 ≤ ai ≤ 100) — 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 test(s)
    input
    1
    1
    
    output
    1
    
    input
    10
    1 2 2 3 4 4 4 2 2 2
    
    output
    8
    
    input
    11
    2 2 2 2 2 2 2 2 2 2 99
    
    output
    1
    题意:从一个数列中任取出一个数,使剩下的数的和是偶数,问共同拥有多少种取法。
    O(n*n)算法 ,非常暴力。

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <vector>
    using namespace std;
    #define LL long long
    int main()
    {
    	int a[110],i,j,n,sum;
    	while(scanf("%d",&n)!=EOF)
    	{
    		int cnt=0;
    		for(i=0;i<n;i++)
    			scanf("%d",a+i);
    		for(i=0;i<n;i++)
    		{
    			sum=0;
    			for(j=0;j<n;j++)
    				if(j!=i)
    					sum+=a[j];
    			if(sum%2==0)
    				cnt++;
    		}
    		printf("%d
    ",cnt);
    	}
    	return 0;
    }


  • 相关阅读:
    【转】系统缓存全解析二:动态缓存(4)-第三方分布式缓存解决方案 Velocity
    DevExpress.XtraTreeList.TreeList 的一些解决办法
    【转】系统缓存全解析二:动态缓存(4)-Discuz!NT中集成Memcached分布式缓存
    c#遍历Dictionary
    【转】memcached 命令概述
    WSAWaitforMultEvent使用
    创建线程是否调用CloseHandle
    小序
    select模式学习(二)之:客户端
    CoInitlize使用
  • 原文地址:https://www.cnblogs.com/mfmdaoyou/p/7001735.html
Copyright © 2011-2022 走看看