BZOJ1088: [SCOI2005]扫雷Mine

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1088

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

题解:水题,发现我们只要知道第一个点就可以推出其他的点,于是我们就可以枚举第一个点,判断可行性。

代码:

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<cmath>
 6 #define N 10005
 7 using namespace std;
 8 int n,ans;
 9 int a[N],b[N];
10 int read()
11 {
12     int x=0; char ch; bool bo=0;
13     while (ch=getchar(),ch<'0'||ch>'9') if (ch=='-') bo=1;
14     while (x=x*10+ch-'0',ch=getchar(),ch>='0'&&ch<='9');
15     if (bo) return -x; return x;
16 }
17 void solve()
18 {
19 
20     b[0]=0; b[1]=1; ans=2;
21     for (int i=2; i<=n+1; i++) {b[i]=a[i-1]-b[i-1]-b[i-2]; if (b[i]<0||b[i]>2||b[n+1])  {ans--; break;}}
22     b[0]=0; b[1]=0;
23     for (int i=2; i<=n+1; i++) {b[i]=a[i-1]-b[i-1]-b[i-2]; if (b[i]<0||b[i]>2||b[n+1]) {ans--; break;}}
24     printf("%d\n",ans);
25 
26 }
27 int main()
28 {
29     n=read();
30     for (int i=1; i<=n; i++) a[i]=read();
31     solve();
32 }
View Code

 

posted @ 2016-06-23 21:56  ACist  阅读(263)  评论(0编辑  收藏  举报