#1094 : Lost in the City
2015-11-20 16:57
309 查看
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
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.
样例输入
样例输出
5 4
解决方法:先对带查找字符数组进行枚举为4种情况,再在原字符数组中进行查找,我用STL的vector 和string来做 ,非常考验基本功和逻辑思维,花了大概6个小时终于AC了
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
using namespace std;
vector<string> Change(vector<string>& vstr)
{
vector<string> vstr2;
string s;
s=vstr[2].substr(0,1)+vstr[1].substr(0,1)+vstr[0].substr(0,1);
vstr2.push_back(s);
s.clear();
s=vstr[2].substr(1,1)+vstr[1].substr(1,1)+vstr[0].substr(1,1);
vstr2.push_back(s);
s.clear();
s=vstr[2].substr(2,1)+vstr[1].substr(2,1)+vstr[0].substr(2,1);
vstr2.push_back(s);
return vstr2;
}
int main()
{
//freopen("in.txt","r",stdin);
int N,M,i,j,k;
string str;
vector<string> street; //字符串动态数组,存储原始街道信息
vector<vector <string > > area(4); //存储小hi周围信息
cin>>N>>M; //N行 M列
for(i=0;i<N;i++)
{
cin>>str;
street.push_back(str);
}
for(i=0;i<3;i++)
{
cin>>str;
area[0].push_back(str);
}
//-----------------开始处理------------------------------
//1、将area转动,枚举为3种情况
area[1]=Change(area[0]);
area[2]=Change(area[1]);
area[3]=Change(area[2]);
//2、查找
int x1,x2,x3,pos=0;
for(i=0;i<N-2;i++)//N-2行查找area的首行
{
for(k=0;k<M-2;k++)//列数
{
for(j=0;j<4;j++) //4个area分别查找
{
x1=street[i].find(area[j][0],k);//返回s2在s1中第一次出现的位置,找不到则返回-1
if(x1!=k)
continue;
else
{
x2=street[i+1].find(area[j][1],x1);
if(x2!=x1)
continue;
else
{
x3=street[i+2].find(area[j][2],x2);
if(x3!=x2)
continue;
else
{
cout<<i+2<<" "<<x3+2<<endl;
pos=x3+1;//新的查找位置
break;
}
}
}
}
// if(pos==0)
// break;
}
}
return 0;
}
单点时限:1000ms
内存限制:256MB
描述
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.样例输入
8 8 ...HSH.. ...HSM.. ...HST.. ...HSPP. PPGHSPPT PPSSSSSS ..MMSHHH ..MMSH.. SSS SHG SH.
样例输出
5 4
解决方法:先对带查找字符数组进行枚举为4种情况,再在原字符数组中进行查找,我用STL的vector 和string来做 ,非常考验基本功和逻辑思维,花了大概6个小时终于AC了
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
using namespace std;
vector<string> Change(vector<string>& vstr)
{
vector<string> vstr2;
string s;
s=vstr[2].substr(0,1)+vstr[1].substr(0,1)+vstr[0].substr(0,1);
vstr2.push_back(s);
s.clear();
s=vstr[2].substr(1,1)+vstr[1].substr(1,1)+vstr[0].substr(1,1);
vstr2.push_back(s);
s.clear();
s=vstr[2].substr(2,1)+vstr[1].substr(2,1)+vstr[0].substr(2,1);
vstr2.push_back(s);
return vstr2;
}
int main()
{
//freopen("in.txt","r",stdin);
int N,M,i,j,k;
string str;
vector<string> street; //字符串动态数组,存储原始街道信息
vector<vector <string > > area(4); //存储小hi周围信息
cin>>N>>M; //N行 M列
for(i=0;i<N;i++)
{
cin>>str;
street.push_back(str);
}
for(i=0;i<3;i++)
{
cin>>str;
area[0].push_back(str);
}
//-----------------开始处理------------------------------
//1、将area转动,枚举为3种情况
area[1]=Change(area[0]);
area[2]=Change(area[1]);
area[3]=Change(area[2]);
//2、查找
int x1,x2,x3,pos=0;
for(i=0;i<N-2;i++)//N-2行查找area的首行
{
for(k=0;k<M-2;k++)//列数
{
for(j=0;j<4;j++) //4个area分别查找
{
x1=street[i].find(area[j][0],k);//返回s2在s1中第一次出现的位置,找不到则返回-1
if(x1!=k)
continue;
else
{
x2=street[i+1].find(area[j][1],x1);
if(x2!=x1)
continue;
else
{
x3=street[i+2].find(area[j][2],x2);
if(x3!=x2)
continue;
else
{
cout<<i+2<<" "<<x3+2<<endl;
pos=x3+1;//新的查找位置
break;
}
}
}
}
// if(pos==0)
// break;
}
}
return 0;
}
相关文章推荐
- 小P的故事——神奇的发票报销
- android里面线程睡眠事件使用方法
- HDU 2874 Connections between cities(LCA离线算法)
- Springmvc 工作原理
- postgresql 客户端登录配置
- RequestMapping定义只能为字母
- kafka topic手动删除及其他相关
- 网络编程
- 关于app的闪退问题
- 小P的故事——神奇的Dota
- UIViewController的生命周期
- 流计算容错
- 这可能是全球发展最快的移动互联网公司
- AutoCAD 插件开发之学习资料
- MVC流程图
- 第一章 scala环境搭建
- 3、手把手教你Extjs5(三)MVVM特性的简单说明
- JSP九大对象
- 【转】JMeter测试有无数据库连接池的性能
- 【转】Jmeter之短板以及建议解决方案