zoukankan      html  css  js  c++  java
  • [HIHO1094]Lost in the City(暴力、枚举)

    题目链接:http://hihocoder.com/problemset/problem/1094

    题意:矩阵里找3*3的子矩阵,按照某个点为中心四个方向的子矩阵符合就行。

    枚举左上角的点,翻转判断即可。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 const int maxn = 220;
     5 int n, m;
     6 char G[maxn][maxn];
     7 char pos[5][5];
     8 bool f[10];
     9 
    10 bool check(int x, int y) {
    11     memset(f, 0, sizeof(f));
    12     for(int i = 0; i < 3; i++) {
    13         for(int j = 0; j < 3; j++) {
    14             if(pos[i][j] != G[x+j][y+i]) f[0] = 1;
    15             if(pos[i][j] != G[x+2-i][y+j]) f[1] = 1;
    16             if(pos[i][j] != G[x+i][y+2-j]) f[2] = 1;
    17             if(pos[i][j] != G[x+2-j][y+2-i]) f[3] = 1;
    18 
    19             if(pos[i][j] != G[x+i][y+j]) f[4] = 1;
    20             if(pos[i][j] != G[x+2-j][y+i]) f[5] = 1;
    21             if(pos[i][j] != G[x+j][y+2-i]) f[6] = 1;
    22             if(pos[i][j] != G[x+2-i][y+2-j]) f[7] = 1;
    23         }
    24     }
    25     if(!(f[0]&&f[1]&&f[2]&&f[3]&&f[4]&&f[5]&&f[6]&&f[7])) return 1;
    26     return 0;
    27 }
    28 
    29 int main() {
    30     // freopen("in", "r", stdin);
    31     while(~scanf("%d%d",&n,&m)) {
    32         memset(G, 0, sizeof(G));
    33         memset(pos, 0, sizeof(pos));
    34         for(int i = 0; i < n; i++) scanf("%s", G[i]);
    35         for(int i = 0; i < 3; i++) scanf("%s", pos[i]);
    36         for(int i = 0; i < n; i++) {
    37             for(int j = 0; j < m; j++) {
    38                 if(check(i, j)) {
    39                     printf("%d %d
    ", i+2, j+2);
    40                 }
    41             }
    42         }
    43     }
    44     return 0;
    45 }
  • 相关阅读:
    2019天梯赛训练1
    Python课程设计 搭建博客
    最容易理解的贪吃蛇小游戏
    数据结构-队列
    数据结构-堆栈(2)
    数据结构-堆栈(1)
    数据结构-线性表(3)
    数据结构-线性表(1)
    linux知识积累
    Maven学习笔记
  • 原文地址:https://www.cnblogs.com/kirai/p/6420224.html
Copyright © 2011-2022 走看看