zoukankan      html  css  js  c++  java
  • HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))

    扫雷

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 998    Accepted Submission(s): 289


    Problem Description
    扫雷游戏是晨晨和小璐特别喜欢的智力游戏,她俩最近沉迷其中无法自拔。
    该游戏的界面是一个矩阵,矩阵中有些格子中有一个地雷,其余格子中没有地雷。 游戏中,格子可能处于己知和未知的状态。如果一个己知的格子中没有地雷,那么该 格子上会写有一个一位数,表示与这个格子八连通相邻的格子中地雷总的数量。
    现在,晨晨和小璐在一个3行N列(均从1开始用连续正整数编号)的矩阵中进 行游戏,在这个矩阵中,第2行的格子全部是己知的,并且其中均没有地雷;而另外 两行中是未知的,并且其中的地雷总数量也是未知的。
    晨晨和小璐想知道,第1行和第3行有多少种合法的埋放地雷的方案。
     
    Input
    包含多组测试数据,第一行一个正整数T,表示数据组数。
    每组数据由一行仅由数字组成的长度为N的非空字符串组成,表示矩阵有3行N 列,字符串的第i个数字字符表示矩阵中第2行第i个格子中的数字。
    保证字符串长度N <= 10000,数据组数<= 100。
     
    Output
    每行仅一个数字,表示安放地雷的方案数mod100,000,007的结果。
     
    Sample Input
    2 22 000
     
    Sample Output
    6 1
     
    Source
     
    Recommend
    jiangzijing2015   |   We have carefully selected several similar problems for you:  5981 5980 5979 5978 5977 
     
    Statistic | Submit | Discuss | Note

    题目链接:

      http://acm.hdu.edu.cn/showproblem.php?pid=5965

    题目大意:

      3*n的扫雷地图,中间一行全为数字。现给中间一行的数字求有多少种合法的雷的方法

      (数字表述当前位置周围8格的雷数)

    题目思路:

      【模拟】

      首先一个雷放在第一行和第三行对第二行的数字的贡献是相同的,所以考虑每一列,如果该列雷数为1则答案*2,否则答案唯一。

      开始时枚举第一列的雷数,接下来可以根据第二行的数字与第i列的雷数推出第i+1列的雷数。

      最后统计答案即可。

     1 //
     2 //by coolxxx
     3 //#include<bits/stdc++.h>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<map>
     9 #include<stack>
    10 #include<queue>
    11 #include<set>
    12 #include<bitset>
    13 #include<memory.h>
    14 #include<time.h>
    15 #include<stdio.h>
    16 #include<stdlib.h>
    17 #include<string.h>
    18 //#include<stdbool.h>
    19 #include<math.h>
    20 #pragma comment(linker,"/STACK:1024000000,1024000000")
    21 #define min(a,b) ((a)<(b)?(a):(b))
    22 #define max(a,b) ((a)>(b)?(a):(b))
    23 #define abs(a) ((a)>0?(a):(-(a)))
    24 #define lowbit(a) (a&(-a))
    25 #define sqr(a) ((a)*(a))
    26 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    27 #define mem(a,b) memset(a,b,sizeof(a))
    28 #define eps (1e-8)
    29 #define J 10000
    30 #define mod 100000007
    31 #define MAX 0x7f7f7f7f
    32 #define PI 3.14159265358979323
    33 #define N 100004
    34 using namespace std;
    35 typedef long long LL;
    36 double anss;
    37 LL aans;
    38 int cas,cass;
    39 int n,m,lll,ans;
    40 char s[N];
    41 int a[N],b[N];
    42 int cal(int y)
    43 {
    44     int x;
    45     a[1]=y;
    46     a[2]=b[1]-a[1];
    47     if(a[2]<0 || a[2]>2)return 0;
    48     x=1+(a[2]==1);
    49     int i;
    50     for(i=2;i<n;i++)
    51     {
    52         a[i+1]=b[i]-a[i]-a[i-1];
    53         if(a[i+1]>2 || a[i+1]<0)return 0;
    54         x=x*(1+(a[i+1]==1))%mod;
    55     }
    56     if(a[1]+a[2]==b[1] && a[n-1]+a[n]==b[n])return x;
    57     else return 0;
    58 }
    59 int main()
    60 {
    61     #ifndef ONLINE_JUDGE
    62     freopen("1.txt","r",stdin);
    63 //    freopen("2.txt","w",stdout);
    64     #endif
    65     int i,j,k;
    66     int x,y,z;
    67 //    init();
    68     for(scanf("%d",&cass);cass;cass--)
    69 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    70 //    while(~scanf("%s",s))
    71 //    while(~scanf("%d%d",&n,&m))
    72     {
    73         scanf("%s",s);
    74         ans=0;n=strlen(s);
    75         for(i=1;i<=n;i++)b[i]=s[i-1]-'0';
    76         //if(b[1])
    77         {//XX
    78             m=cal(0);
    79             ans=(ans+m)%mod;
    80         }
    81         {//OX XO
    82             m=cal(1);
    83             ans=((ans+m)%mod+m)%mod;
    84         }
    85         {//OO
    86             m=cal(2);
    87             ans=(ans+m)%mod;
    88         }
    89         printf("%d
    ",ans);
    90     }
    91     return 0;
    92 }
    93 /*
    94 //
    95 
    96 //
    97 */
    View Code
  • 相关阅读:
    The Mac Application Environment 不及格的程序员
    Xcode Plugin: Change Code In Running App Without Restart 不及格的程序员
    The property delegate of CALayer cause Crash. 不及格的程序员
    nil localizedTitle in SKProduct 不及格的程序员
    InApp Purchase 不及格的程序员
    Safari Web Content Guide 不及格的程序员
    在Mac OS X Lion 安装 XCode 3.2 不及格的程序员
    illustrate ARC with graphs 不及格的程序员
    Viewing iPhoneOptimized PNGs 不及格的程序员
    What is the dSYM? 不及格的程序员
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/6078888.html
Copyright © 2011-2022 走看看