SGU239. Minesweeper 及 SCOI 2005 扫雷

题目描述 Description

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

输入描述 Input Description

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

输出描述 Output Description

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

样例输入 Sample Input

2
1 1

样例输出 Sample Output

2

题解:

通过右边给出的数字推出左边的,每一个格子放的雷都是有它右上方的雷数减去它前两个格子的雷数所得到的。

PS:

强烈谴责scoi的出题人。。。从国外题库上扒题算那门子事,这种对选手极其不负责的行为应该给予严惩

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int xl[23333];
int num[23333];
int n, tot = 0;
bool check()
{
    for (int i = 1; i <= n; i++)
    {
        xl[i+1] = num[i] - xl[i] - xl[i-1];
        if (xl[i+1] < 0 || xl[i+1] > 1)
            return 0;
    }
    return !xl[n+1];
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        scanf("%d", &num[i]);
    if (num[1] == 0)
        tot += check();
    else if (num[1] == 1)
    {
        xl[1] = 1;
        tot += check();
        memset (xl, 0, sizeof(xl));
        xl[2] = 1;
        tot += check();
    }
    else
    {
        xl[1] = 1;
        xl[2] = 1;
        tot += check();
    }
    cout << tot;
    return 0;
}

 

上一篇
下一篇