zoukankan      html  css  js  c++  java
  • BZOJ1088(SCOI2005)

    枚举第一行第一个格子的状态(有雷或者无雷,0或1),然后根据第一个格子推出后面所有格子的状态。推出之后判断解是否可行即可。

    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define REP(i,n)                for(int i(0); i <  (n); ++i)
    #define rep(i,a,b)              for(int i(a); i <= (b); ++i)
    #define dec(i,a,b)              for(int i(a); i >= (b); --i)
    #define for_edge(i,x)           for(int i = H[x]; i; i = X[i])
    
    #define LL      long long
    #define ULL     unsigned long long
    #define MP      make_pair
    #define PB      push_back
    #define FI      first
    #define SE      second
    #define INF     1 << 30
    
    const int N     =    100000      +       10;
    const int M     =    10000       +       10;
    const int Q     =    1000        +       10;
    const int A     =    30          +       1;
    
    int a[N], b[N];
    int n;
    int ans;
    
    int main(){
    #ifndef ONLINE_JUDGE
    	freopen("test.txt", "r", stdin);
    	freopen("test.out", "w", stdout);
    #endif
    
    	scanf("%d", &n);
    	rep(i, 1, n) scanf("%d", a + i);
    	rep(i, 0, 1){
    		bool flag = true;
    		b[1] = i;
    		rep(j, 2, n) b[j] = a[j - 1] - b[j - 1] - b[j - 2];
    		rep(j, 2, n - 1) if (b[j] < 0 || b[j] > 1){ flag = false; break;}
    		if (b[n] < 0 || b[n] > 1) flag = false;
    		rep(j, 1, n) if (b[j - 1] + b[j] + b[j + 1] != a[j]){ flag = false; break;}
    		//rep(j, 1, n) printf("%d ", b[j]); putchar(10);
    
    		if (flag) ++ans;
    	}
    
    	printf("%d
    ", ans);
    
    
    
    	return 0;
    
    }
    


  • 相关阅读:
    hash表及带注释插头dp
    NOIP模拟测试9「随·单·题」
    静态点分治总结
    NOIP模拟测试8「匹配·回家」
    NOIP模拟测试8「寿司」
    「PKUWC2018」Slay the Spire
    矩阵快速幂总结
    SQL中的object_id函数
    SQL数据库Replace的用法
    SQL批量提交修改业务
  • 原文地址:https://www.cnblogs.com/cxhscst2/p/6648801.html
Copyright © 2011-2022 走看看