码迷,mamicode.com
首页 > 其他好文 > 详细

luogu P2327 [SCOI2005]扫雷

时间:2018-11-15 19:41:37      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:n+1   uri   algo   str   lin   printf   答案   for   temp   

很好的一道题,仔细思索(在y^3 dalao的帮助下)可以发现答案只有0 1 2三种情况
直接枚举第一位有没有雷,就可以递推了qwq

附上y^3大佬的blogs https://blog.csdn.net/Y_Y_Y_3

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
template<class T>void read(T &x){
    int f=0;x=0;char ch=getchar();
    while(ch<'0'||ch>'9')  {f|=(ch=='-');ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
} 

const int N=10007;
int a[N],ans[N];
int yyy,n;
bool b[N];

inline bool yhh(bool qwq){
    memset(b,0,sizeof(b));
    b[1]=qwq;
    for(int i=1;i<=n;++i)
        if(b[i-1]+b[i]+1==a[i]) 
            b[i+1]=1;
    if(b[n+1]) return 0;
    for(int i=1;i<=n;++i)
        if(b[i-1]+b[i]+b[i+1]!=a[i])
            return 0;
    
    return 1;
}

int main(){
    read(n);
    for(int i=1;i<=n;++i)
        read(a[i]);
    if((n==1&&a[1]>1)||(n==2&&a[1]+a[2]>=5)){
        printf("0\n");
        return 0;
    }
    printf("%d\n",yhh(1)+yhh(0));
    return 0;
}

luogu P2327 [SCOI2005]扫雷

标签:n+1   uri   algo   str   lin   printf   答案   for   temp   

原文地址:https://www.cnblogs.com/Peper/p/9965422.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!