首页 > 代码库 > poj2612Mine Sweeper

poj2612Mine Sweeper

很简单的模拟题目,但在队内赛的时候一直WA了10发。。。我ca

题目没看懂,也不算,就是我以为摸到地雷他会标星(*) ,但其实还是(x),T_T

  1 #include <cstdio>  2 #include <iostream>  3 #include <cstring>  4 using namespace std;  5   6 int n;  7 bool tag = false;  8 char graph1[15][15];  9 char graph2[15][15]; 10 char graph3[15][15]; 11  12 int mov[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; 13  14 bool check(int x, int y) 15 { 16     if(x >= 0 && y >= 0 && x < n && y < n) 17         return true; 18     return false; 19 } 20  21 int handle(int i, int j) 22 { 23     int sum = 0; 24     for(int k = 0; k < 8; ++k) 25     { 26         int x = mov[k][0] + i; 27         int y = mov[k][1] + j; 28         if(check(x, y) && graph1[x][y] == *) 29         { 30             sum++; 31         } 32     } 33     return sum; 34 } 35  36 int main() 37 { 38  39     int i, j; 40     while(scanf("%d%*c", &n) != EOF) 41     { 42         memset(graph1, 0, sizeof(graph1)); 43         memset(graph2, 0, sizeof(graph2)); 44         memset(graph3, 0, sizeof(graph3)); 45  46         for(i = 0; i < n; ++i) 47         { 48            gets(graph1[i]); 49            //puts(graph1[i]); 50         } 51         for(i = 0; i < n; ++i) 52         { 53             gets(graph2[i]); 54             //puts(graph2[i]); 55         } 56  57         for(i = 0; i < n; ++i) 58         { 59             for(j = 0; j < n; ++j) 60             { 61                 if(graph2[i][j] == x && graph1[i][j] == *) 62                     tag = true; 63             } 64         } 65  66         if(tag == false) 67         { 68             for(i = 0; i < n; ++i) 69             { 70                 for(j = 0; j < n; ++j) 71                 { 72                     if(graph2[i][j] == x) 73                     { 74                         graph3[i][j] = 0 + handle(i, j); 75                     } 76                     else 77                     { 78                         graph3[i][j] = .; 79                     } 80                 } 81             } 82         } 83         else 84         { 85             for(i = 0; i < n; ++i) 86             { 87                 for(j = 0; j < n; ++j) 88                 { 89                     if(graph1[i][j] != * && graph2[i][j] == x) 90                     { 91                         graph3[i][j] = 0 + handle(i, j); 92                     } 93                     else if(graph2[i][j] == . && graph1[i][j] == *) 94                     { 95                         graph3[i][j] = *; 96                     } 97                     else if(graph2[i][j] == x && graph1[i][j] == *) 98                     { 99                         graph3[i][j] = *;100                     }101                     else102                     {103                         graph3[i][j] = .;104                     }105                 }106             }107         }108 109         for(i = 0; i < n; ++i)110         {111             puts(graph3[i]);112         }113     }114     return 0;115 }
View Code

 

poj2612Mine Sweeper