zoukankan      html  css  js  c++  java
  • bzoj 1088: [SCOI2005]扫雷Mine

    题目链接

    1088: [SCOI2005]扫雷Mine

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 2525  Solved: 1495
    [Submit][Status][Discuss]

    Description

    相信大家都玩过扫雷的游戏。那是在一个n*m的矩阵里面有一些雷,要你根据一些信息找出雷来。万圣节到了,“余”人国流行起了一种简单的扫雷游戏,这个游戏规则和扫雷一样,如果某个格子没有雷,那么它里面的数字表示和它8连通的格子里面雷的数目。现在棋盘是n×2的,第一列里面某些格子是雷,而第二列没有雷,如下图: 由于第一列的雷可能有多种方案满足第二列的数的限制,你的任务即根据第二列的信息确定第一列雷有多少种摆放方案。

    Input

    第一行为N,第二行有N个数,依次为第二列的格子中的数。(1<= N <= 10000)

    Output

    一个数,即第一列中雷的摆放方案数。

    Sample Input

    2
    1 1

    Sample Output

    2
     
    确定了第一行的情况之后其他的都可以推出来。
    #include <iostream>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #include <set>
    #include <string>
    #include <queue>
    #include <stack>
    #include <bitset>
    using namespace std;
    #define pb(x) push_back(x)
    #define ll long long
    #define mk(x, y) make_pair(x, y)
    #define lson l, m, rt<<1
    #define mem(a) memset(a, 0, sizeof(a))
    #define rson m+1, r, rt<<1|1
    #define mem1(a) memset(a, -1, sizeof(a))
    #define mem2(a) memset(a, 0x3f, sizeof(a))
    #define rep(i, n, a) for(int i = a; i<n; i++)
    #define fi first
    #define se second
    typedef pair<int, int> pll;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int mod = 1e9+7;
    const int inf = 1061109567;
    const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
    int a[10005], f[10005], ans, n;
    int cal() {
        for(int i = 1; i<=n; i++) {
            f[i+1] = a[i]-f[i-1]-f[i];
            if(f[i+1]<0)
                return 0;
        }
        if(a[n]!=f[n]+f[n-1])
            return 0;
        return 1;
    }
    int main()
    {
        cin>>n;
        for(int i = 1; i<=n; i++) {
            scanf("%d", &a[i]);
        }
        if(a[1] == 0) {
            ans += cal();
        } else if(a[1] == 1) {
            f[1] = 1;
            ans += cal();
            mem(f);
            f[2] = 1;
            ans += cal();
        } else {
            f[1] = f[2] = 1;
            ans += cal();
        }
        cout<<ans<<endl;
        return 0;
    }
  • 相关阅读:
    测试工具iometer, iozone, bonnie++
    python 解析properties文件的工具类
    Linux文件系统性能测试工具fdtree和iozone
    python的WEB容器框架
    iozone的介绍与使用
    Python 的 SOAP 实现
    在powerpoint2007里,如何改变模板里的背景图形
    python的接口和抽象类
    决策树算法总结
    C++ 重载、覆盖和隐藏
  • 原文地址:https://www.cnblogs.com/yohaha/p/5234008.html
Copyright © 2011-2022 走看看