zoukankan      html  css  js  c++  java
  • 【BZOJ1088】扫雷

    1088: [SCOI2005]扫雷Mine

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 3598  Solved: 2110
    [Submit][Status][Discuss]

    Description

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

    Input

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

    Output

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

    Sample Input

    2
    1 1

    Sample Output

    2

    HINT

     

    Source

    sol:

    三种情况:

    我们只考虑第一个位置和第二个位置影响是什么,枚举是否有雷

    发现接下来的假如都符合 那么雷数肯定是a[i-1]-f[i-1]-f[i-2] 最后特判一下最后一个就好

    算是模拟的dp

    /*To The End Of The Galaxy*/
    #include<cstdio>
    #include<cstdlib>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<iomanip>
    #include<stack>
    #include<map>
    #include<set>
    #include<cmath>
    #include<complex>
    #define debug(x) cerr<<#x<<"="<<x<<endl
    #define INF 0x7f7f7f7f
    #define llINF 0x7fffffffffffll
    using namespace std;
    typedef pair<int,int> pii;
    typedef long long ll;
    inline int init()
    {
        int now=0,ju=1;char c;bool flag=false;
        while(1)
        {
            c=getchar();
            if(c=='-')ju=-1;
            else if(c>='0'&&c<='9')
            {
                now=now*10+c-'0';
                flag=true;
            }
            else if(flag)return now*ju;
        }
    }
    inline long long llinit()
    {
        long long now=0,ju=1;char c;bool flag=false;
        while(1)
        {
            c=getchar();
            if(c=='-')ju=-1;
            else if(c>='0'&&c<='9')
            {
                now=now*10+c-'0';
                flag=true;
            }
            else if(flag)return now*ju;
        }
    }
    int a[10005];
    int f[10005];
    int n;
    int judge()
    {
        for(int i=3;i<=n;i++)
        {
            f[i]=a[i-1]-f[i-1]-f[i-2];
            if(f[i]<0)return 0;
        }
        if(f[n-1]+f[n]!=a[n])return 0;
        return 1;
    }
    int main()
    {
        int ans=0;
        n=init();
        for(int i=1;i<=n;i++)a[i]=init();
        if(a[1]==0)
        {
            f[1]=0;f[2]=0;
            ans+=judge();
        }
        else if(a[1]==1)
        {
            f[1]=1;ans+=judge();memset(f,0,sizeof(f));
            f[1]=0;f[2]=1;ans+=judge();
        }
        else 
        {
            f[1]=1;f[2]=1;ans+=judge();
        }
        printf("%d
    ",ans);
        return 0;
    }
    View Code
  • 相关阅读:
    [Swift]LeetCode1093. 大样本统计 | Statistics from a Large Sample
    [Swift]鸡尾酒排序 | Cocktail Sort
    [Swift]插入排序 | Insertion sort
    [Swift]求最大公约数和最小公倍数
    [Swift]LeetCode1087. 字母切换 | Permutation of Letters
    [Swift]LeetCode1086. 前五科的均分 | High Five
    [Swift]LeetCode1088. 易混淆数 II | Confusing Number II
    [Swift]LeetCode1090. 受标签影响的最大值 | Largest Values From Labels
    [Swift]LeetCode1091. 二进制矩阵中的最短路径 | Shortest Path in Binary Matrix
    [Swift]LeetCode1092. 最短公共超序列 | Shortest Common Supersequence
  • 原文地址:https://www.cnblogs.com/redwind/p/6669242.html
Copyright © 2011-2022 走看看