zoukankan      html  css  js  c++  java
  • 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
    ", ans);
        return 0;
    }
  • 相关阅读:
    2017-12 CDQZ集训(已完结)
    BZOJ1492 货币兑换 CDQ分治优化DP
    BZOJ2001 [Hnoi2010]City 城市建设 CDQ分治
    树套树小结
    跑路了
    NOI2020 游记
    半平面交模板
    Luogu 3245 大数
    Luogu 3246 序列
    test20190408(十二省联考)
  • 原文地址:https://www.cnblogs.com/widsom/p/9277876.html
Copyright © 2011-2022 走看看