【BZOJ 1088】[SCOI2005]扫雷Mine

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

第一个位置确定了。 那么可以通过a[i-1]来推测出第i个位置应该放什么。 所以分两种情况就好。 第一个位置为0 或第一个位置为1 最多只有这两种可能。 判断合法性就好。

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1
using namespace std;

const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 1e4;

int n,a[N+10],b[N+10];

bool ok(int x){
    b[1] = x;
    for (int i = 2;i <= n;i++){
        int should = a[i-1];
        int actual = b[i-2] + b[i-1];
        if (should-actual ==1){
            b[i] = 1;
        }else if (should - actual ==0){
            b[i] = 0;
        }else return false;
    }
    if (b[n-1]+b[n]!=a[n]) return false;
    return true;
}

int main(){
	#ifdef LOCAL_DEFINE
	    freopen("rush_in.txt", "r", stdin);
	#endif
    scanf("%d",&n);
    rep1(i,1,n) scanf("%d",&a[i]);
    int ans = 0;
    for (int i = 0;i <= 1;i++) if (ok(i)) ans++;
    printf("%d\n",ans);
	return 0;
}

posted @ 2018-03-15 14:40  AWCXV  阅读(100)  评论(0编辑  收藏  举报