BZOJ 1088: [SCOI2005]扫雷Mine

1088

思路:

模拟,确定第1和2格后所有的格子都能确定

代码:

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<int,pii>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

const int N = 1e5 + 5;
int a[N], f[N], n;
int check() {
    for (int i = 2; i <= n; i++) {
        f[i+1] = a[i] - f[i] - f[i-1];
        if(f[i+1] < 0 || f[i+1] > 1) return 0;
    }
    return f[n+1] == 0;
}
int main() {
    int ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    if(a[1] == 0) {
        ans += check();
    }
    else if(a[1] == 1) {
        f[1] = 1;
        ans += check();
        mem(f, 0);
        f[2] = 1;
        ans += check();
    }
    else {
        f[1] = 1;
        f[2] = 1;
        ans += check();
    }
    printf("%d\n", ans);
    return 0;
}

 

posted @ 2018-07-07 17:31  Wisdom+.+  阅读(...)  评论(... 编辑 收藏