bzoj1088 [SCOI2005]扫雷

来源:互联网 发布:三国志9优化伴侣 编辑:程序博客网 时间:2024/04/29 22:50

这么水的题我居然还WA了好几次 我觉得这个是bzoj上除了a+b以外最水的题了吧……
想法非常简单
只要确定了第一格和第二格有没有雷 接下来都可以推出来
所以我们就暴力的枚举一下前两个格的情况 推出接下来所有雷的位置 然后看一下合不合法就好了
说起来很简单不过写的时候还是犯错了 我好蠢啊

#include <cstdio>using namespace std;const int N=10005;int n=0,a[N],b[N],ans=0;inline int judge(int x1,int x2) {    b[1]=x1;    b[2]=x2;    if (x1+x2!=a[1] || x1+x2>a[2])        return 0;    for (int i=3;i<=n;++i) {        b[i]=a[i-1]-b[i-1]-b[i-2];        if (b[i]>1 || b[i]<0 || b[i-1]+b[i]>a[i] || b[i-1]+b[i]-a[i]>=2)            return 0;        }                        if (a[n]!=b[n]+b[n-1])        return 0;    return 1;}int main(void) {    scanf("%d",&n);    for (int i=1;i<=n;++i)        scanf("%d",a+i);    switch (n) {        case 1:{            ans=a[1]<=1?1:0;                    break;        }        case 2:{            if (a[1]==1 && a[2]==1 )                ans=2;            else if (a[1]==2 && a[2]==2 || a[1]==0 && a[2]==0)                ans=1;            else                ans=0;            break;        }        default:            ans+=judge(0,0)+judge(0,1)+judge(1,0)+judge(1,1);    }    printf("%d\n",ans);        return 0;}
0 0
原创粉丝点击