hihocoder 第68周 题目1 : Lost in the City
来源:互联网 发布:四季彩软件下载 编辑:程序博客网 时间:2024/06/08 10:08
此题只得了30分,但思路没有错误。可能是边界条件有问题。和图像的模板匹配有些相似。
题目1 : Lost in the City
- 样例输入
8 8...HSH.....HSM.....HST.....HSPP.PPGHSPPTPPSSSSSS..MMSHHH..MMSH..SSSSHGSH.
- 样例输出
5 4
描述
Little Hi gets lost in the city. He does not know where he is. He does not know which direction is north.
Fortunately, Little Hi has a map of the city. The map can be considered as a grid of N*M blocks. Each block is numbered by a pair of integers. The block at the north-west corner is (1, 1) and the one at the south-east corner is (N, M). Each block is represented by a character, describing the construction on that block: '.' for empty area, 'P' for parks, 'H' for houses, 'S' for streets, 'M' for malls, 'G' for government buildings, 'T' for trees and etc.
Given the blocks of 3*3 area that surrounding Little Hi(Little Hi is at the middle block of the 3*3 area), please find out the position of him. Note that Little Hi is disoriented, the upper side of the surrounding area may be actually north side, south side, east side or west side.
输入
Line 1: two integers, N and M(3 <= N, M <= 200).
Line 2~N+1: each line contains M characters, describing the city's map. The characters can only be 'A'-'Z' or '.'.
Line N+2~N+4: each line 3 characters, describing the area surrounding Little Hi.
输出
Line 1~K: each line contains 2 integers X and Y, indicating that block (X, Y) may be Little Hi's position. If there are multiple possible blocks, output them from north to south, west to east.
#include<iostream>using namespace std;char s[207][207];char t[3][3],tr90[3][3],tr180[3][3],tr270[3][3];void rotate(char t1[3][3],char t2[3][3]){ for(int i=0;i<3;++i) for(int j=0;j<3;++j) t2[i][j]=t1[2-j][i];}int check(char s[][207],char p[][3],int g,int h){ int flag=1; for(int i=0;i<3;++i) for(int j=0;j<3;++j) if(s[g+i][h+j]!=p[i][j]) flag=0; if(flag==1) return 1; else return 0;}int main(){ int n,m; cin>>n>>m; for(int i=0;i<n;++i) //for(int j=1;j<=m;++j) cin>>s[i]; for(int i=0;i<3;++i) //for(int j=0;j<3;++j) cin>>t[i]; rotate(t,tr90); rotate(tr90,tr180); rotate(tr180,tr270); for(int i=0;i<n-2;++i) for(int j=0;j<m-2;++j) { int flag=0; flag|=check(s,t,i,j); flag|=check(s,tr90,i,j); flag|=check(s,tr180,i,j); flag|=check(s,tr270,i,j); if(flag){ cout<<i+2<<" "<<j+2<<endl; return 0;} } return 0;}
- hihocoder 第68周 题目1 : Lost in the City
- hihocoder:Lost in the City
- hihocoder#1094 Lost in the City
- hihoCoder 1094 Lost in the City
- 【hihocoder】1094. lost in the City
- HIHOCODER#1094 : Lost in the City
- hihocoder-#1094 : Lost in the City
- hihoCoder题库1094Lost in the City
- hihocoder #1094 : Lost in the City
- 【hihocoder】#1094 : Lost in the City
- hihoCoder #1094 : Lost in the City
- hihocoder 1094 : Lost in the City
- hihocoder #1094 : Lost in the City
- hihoCoder - 1094 - Lost in the City (暴力枚举!!)
- Lost in the City
- Lost in the City
- #1094 : Lost in the City
- #1094 Lost in the City
- 九度OJ 1034:寻找大富翁 (排序)
- HDU 5504:GT and sequence
- 题目9:MySQL---------Department Top Three Salaries
- hdu acm 3033 I love sneakers!
- VNC在工业上的应用,及其与360的冲突
- hihocoder 第68周 题目1 : Lost in the City
- 九度OJ 1035:找出直系亲属 (二叉树、递归)
- ES6 的初步了解(一)
- Android Context对象
- fatal error C1083: 无法打开包括文件: “SDKDDKVer.h”: No such file or directory
- 使表单居中的方式
- Eclipse向Android Studio工程的完美迁移
- ZOJ2478
- ios学习之alertView的基本使用