lost in the city(超时了...)
来源:互联网 发布:bulkrequest java 编辑:程序博客网 时间:2024/04/27 21:52
#include <string>#include <vector>#include <iostream>#include <algorithm>#include <utility>using namespace std;bool isPattern(const string &str1,const string &str2){if(str1.length()==str2.length()){for(int i=0;i<str1.length();i++){if(str1[i]!=str2[i])return false;}return true;}elsereturn false;}void updownPattern(vector<string> &vec,vector<string> &vec2,vector<pair<int,int>> &ret){int i,j;int N=vec.size();int M=vec[0].size();vector<string> vec3(vec);pair<int,int> p;for(auto &s:vec3)reverse(s.begin(),s.end());reverse(vec3.begin(),vec3.end());//上面是北面的情况for(i=0;i<N-2;i++){for(j=0;j<M-2;j++)if(isPattern(vec[i].substr(j,3),vec2[0]) &&isPattern(vec[i+1].substr(j,3),vec2[1]) &&isPattern(vec[i+2].substr(j,3),vec2[2])){ p=make_pair(i+2,j+2); if(find(ret.begin(),ret.end(),p)==ret.end())ret.push_back(p);}}//上面是南面的情况for(i=0;i<N-2;i++){for(j=0;j<M-2;j++)if(isPattern(vec3[i].substr(j,3),vec2[0])&&isPattern(vec3[i+1].substr(j,3),vec2[1])&&isPattern(vec3[i+2].substr(j,3),vec2[2])){ p=make_pair(N-(i+1),M-(j+1)); if(find(ret.begin(),ret.end(),p)==ret.end())ret.push_back(p);}}}void lrPattern(vector<string> &vec,vector<string> &vec2,vector<pair<int,int>>&ret){int i,j;int N=vec.size();int M=vec[0].size();vector<string> vec3(vec);pair<int,int> p;for(auto &s:vec3)reverse(s.begin(),s.end());reverse(vec3.begin(),vec3.end());//上面是西边的情况for(i=0;i<N-2;i++){for(j=0;j<M-2;j++)if(isPattern(vec[i].substr(j,3),vec2[0])&&isPattern(vec[i+1].substr(j,3),vec2[1])&&isPattern(vec[i+2].substr(j,3),vec2[2])){ p=make_pair(M-(j+1),i+2); if(find(ret.begin(),ret.end(),p)==ret.end())ret.push_back(p);}}//上面是东边的情况for(i=0;i<N-2;i++){for(j=0;j<M-2;j++)if(isPattern(vec3[i].substr(j,3),vec2[0])&&isPattern(vec3[i+1].substr(j,3),vec2[1])&&isPattern(vec3[i+2].substr(j,3),vec2[2])){p=make_pair(j+2,N-(i+1)); if(find(ret.begin(),ret.end(),p)==ret.end())ret.push_back(p);}}}int main(){int N,M;cin>>N>>M;vector<string> strs1;vector<string> strs2(M);vector<string> strs3;string line;getline(cin,line);for(int i=0;i<N;i++){ getline(cin,line);strs1.push_back(line);}while(getline(cin,line)){strs3.push_back(line);}for(int i=0;i<strs1.size();i++)//按竖读入strs2{for(int j=0;j<M;j++)strs2[j]+=strs1[i][j];}//将strs2反转for(auto &s:strs2)reverse(s.begin(),s.end());vector<pair<int,int>> ret;updownPattern(strs1,strs3,ret);lrPattern(strs2,strs3,ret);stable_sort(ret.begin(),ret.end(), [](const pair<int,int> &a,const pair<int,int> &b) {return (a.first<b.first);});stable_sort(ret.begin(),ret.end(), [](const pair<int,int> &a,const pair<int,int> &b) {return (a.first==b.first)&&(a.second<b.second);});for(auto p:ret)cout<<p.first<<" "<<p.second<<endl;return 0;}
0 0
- lost in the city(超时了...)
- Lost in the City
- Lost in the City
- #1094 : Lost in the City
- #1094 Lost in the City
- #1094 : Lost in the City
- hihocoder:Lost in the City
- lost in the city(枚举)
- Lost in the City hihoCoder1094
- 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
- hihoCoder题库1094Lost in the City
- hihocoder #1094 : Lost in the City
- 【hihocoder】#1094 : Lost in the City
- 实现3天订单自动取消
- 使用Python实现OAuth2.0认证服务器
- 《算法导论》5、冒泡排序实现(C++)
- 解决oracle乱码问题。
- centos升级python
- lost in the city(超时了...)
- 枚举类型应用(一)
- 黑马程序员——java学习笔记--网络编程
- C和C++实现方式
- 浅谈android am命令
- FUNCTION 'F4_DATE'在DIALOG程序中的应用
- 红黑树理解 - 数据结构
- 如何给C控制台程序添加图标【抄的】
- FireMonkey开发: Android和IOS下的剪贴板实现