lost in city (修改后,时间大幅度减少,所以系统的find函数还是挺耗时的)
来源:互联网 发布:我国网络犯罪原因分析 编辑:程序博客网 时间:2024/06/06 00:32
#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 upPattern(vector<string> &vec,vector<string> &vec2,vector<pair<int,int>> &ret){int i,j;int N=vec.size();int M=vec[0].size();//上面是北面的情况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])) ret.push_back(make_pair(i+2,j+2));}}void downPattern(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);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(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])) ret.push_back(make_pair(N-(i+1),M-(j+1)));}}void leftPattern(vector<string> &vec,vector<string> &vec2,vector<pair<int,int>>&ret){int i,j;int N=vec.size();int M=vec[0].size();//上面是西边的情况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])){ ret.push_back(make_pair(M-(j+1),i+2));}}}void rightPattern(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(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]))ret.push_back(make_pair(j+2,N-(i+1)));}}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;upPattern(strs1,strs3,ret);downPattern(strs1,strs3,ret);leftPattern(strs2,strs3,ret);rightPattern(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);});vector<pair<int,int>> ret2;ret2.push_back(ret[0]);for(int i=1;i<ret.size();i++)if(ret[i]!=ret[i-1])ret2.push_back(ret[i]);for(auto v:ret2)cout<<v.first<<" "<<v.second<<endl;return 0;}
0 0
- lost in city (修改后,时间大幅度减少,所以系统的find函数还是挺耗时的)
- 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
- #1094 : Lost in the City 找到几个当年c语言留下的坑
- 减少应用启动时的耗时
- 的大幅度
- 修改系统日期的代码。不耗时,很快
- 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
- 小记 正则(一)
- codeforces63E Sweets Game DP,dfs,博弈
- thinking in java第十天
- 【Storm 入门】 Blot分流
- 听说东方素养要上央视?
- lost in city (修改后,时间大幅度减少,所以系统的find函数还是挺耗时的)
- 简单的无扩展Vim配置文件
- hdu1506---Largest Rectangle in a Histogram(单调栈)
- IOS学习 copy的一些认识
- HDU----1253胜利大逃亡 BFS
- C语言比较重要的库函数memcpy memmove和内存重叠的问题
- eclipse下导入android源码
- 在widows 2008 x64bit R2下安装Oracle db 10.2.0.4时遇到的"检查操作系统版本: 必须是5.1 or 5.2。实际为 6.1未通过"
- hdu 2106 decimal system