Atcoder #017 agc017 A.Biscuits 简单数学

LINK

题意:水题 求取数,使得和为奇数或偶数的方案数。

思路:统计奇数和偶数,组合求一下发现结果就是$2^{odd-1} + 2^{eve-1}$ 注意特殊情况,即奇数个为0又要求和为奇数的方案数为0,其他情况最小也有1。然后就是很脑残的因为数据范围比赛中交了2次WA,本来写的就慢半天才看出来是2的幂次,还错两次...

/** @Date    : 2017-07-09 19:57:01
  * @FileName: A.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;


int n, p;
LL a[N];
LL odd, eve;
int main()
{
	while(cin >> n >> p)
	{
		odd = eve = 0;
		for(int i = 0; i < n; i++)
		{
			scanf("%lld", a + i);
			if(a[i] % 2)
				odd++;
			else eve++;
		}
		LL ans = 1LL;
		ans = 1LL << (eve);//这里忘了LL了
		if(odd != 0)
			ans *= 1LL << (odd - 1LL);
		if(odd == 0 && p == 1)
			ans = 0;
		printf("%lld
", ans);
	}
    return 0;
}
原文地址:https://www.cnblogs.com/Yumesenya/p/7145421.html