题目大意:
给出长度为n的两列,其中一列有
分析:
稍微脑补一下我们可以发现只要确定了第一个那么整列都确定了。so我们枚举第一个再判断就行了。
AC code:
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#define ONLINE_JUDGE
typedef long long LL;
typedef double DB;
typedef long double LD;
using namespace std;
const int MAXN = 1009;
int n;
int s[MAXN];
int f[MAXN];
bool check(int x)
{
memset(f, 0, sizeof(f));
f[1] = x;
for(int i = 1; i <= n; ++i)
{
f[i+1] = s[i]-f[i]-f[i-1];
if(f[i+1] < 0 || f[i+1] > 1) return false;
}
return f[n+1] == 0;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("sgu239.in", "r", stdin);
freopen("sgu239.out", "w", stdout);
#endif
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", s+i);
printf("%d\n", check(0)+check(1));
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}