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

hihocoder-1094-Lost in the City

时间:2016-09-09 00:44:33      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

n*m的矩阵,再输入一个3*3的矩阵,找出在大的矩阵中这个3*3的矩阵的位置(3*3的矩阵可旋转),当有多个答案是,从上到下,从左到右的顺序输出

(3 <= N, M <= 200).

分析:数据范围不大,直接暴力,在n*m的矩阵中枚举3*3矩阵的右上点,然后比较这个3*3是否和输入的3*3的矩阵旋转后相同

 1 #include<iostream>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<vector>
 5 #include<string>
 6 using namespace std;
 7 
 8 int n,m;
 9 char a[300][300];
10 char b[10][10];
11 
12 void rat()
13 {
14     char tmp[10];
15     tmp[0]=b[0][0];
16     tmp[1]=b[1][0];
17     tmp[2]=b[2][0];
18     b[0][0]=b[2][0];
19     b[1][0]=b[2][1];
20     b[2][0]=b[2][2];
21     b[2][1]=b[1][2];
22     b[2][2]=b[0][2];
23     b[1][2]=b[0][1];
24     b[0][2]=tmp[0];
25     b[0][1]=tmp[1];
26     b[0][0]=tmp[2];
27 }
28 
29 bool chk(int i,int j)
30 {
31     for(int u=0;u<3;u++){
32         for(int v=0;v<3;v++){
33             if(i+u>n-1||j+v>m-1||a[i+u][j+v]!=b[u][v]) return false;
34         }
35     }
36     return true;
37 }
38 
39 void func()
40 {
41     for(int i=0;i<n;i++){
42         for(int j=0;j<m;j++){
43             for(int k=0;k<4;k++){
44                 rat();
45                 if(chk(i,j)){
46                     cout<<i+2<<" "<<j+2<<endl;
47                     break;
48                 }
49             }
50         }
51     }   
52 }
53 
54 int main()
55 {
56     while(cin>>n>>m){
57         for(int i=0;i<n;i++) cin>>a[i];
58         for(int i=0;i<3;i++) cin>>b[i];
59         func();
60     }
61 }

 

hihocoder-1094-Lost in the City

标签:

原文地址:http://www.cnblogs.com/0summer/p/5855005.html

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