HDOJ 5024 Wang Xifeng's Little Plot
来源:互联网 发布:股市模拟软件哪个好 编辑:程序博客网 时间:2024/06/05 19:05
#include<cstdio>#include<cstring>#include<vector>#include<algorithm>#include<iostream>#include<string>#include<queue>#include<stack>#include<cmath>#include<cctype>#include<map>#include<set>#include<sstream>using namespace std;const int OO=(1<<30);typedef long long LL;struct Path{ int from; int len; int to; int dir;///路径的走向 Path(int from,int to,int len,int dir):from(from),to(to),len(len),dir(dir){} bool operator<(const Path& rhs)const{ if(from<rhs.from)return true; return false; }};vector<Path>paths;const int maxn=110;const int dr[]={-1,1,0,0,1,-1,1,-1};///北,南,西,东,东南,东北,西南,西北const int dc[]={0,0,-1,1,1,1,-1,-1};bool is_rec(int i,int j){ if(i>j)swap(i,j); if( (i==0 || i==1) && (j==2 || j==3) )return true; if( (i==2 || i==3) && (j==1 || j==0) )return true; if( (i==4 || i==7) && (j==5 || j==6) )return true; if( (i==5 || i==6) && (j==4 || j==7) )return true; return false;}char net[maxn][maxn];int R;int main(){ while(scanf("%d",&R) && R){ for(int i=0;i<R;i++) scanf("%s",net[i]); paths.clear();int ans=-OO; for(int from=0;from<R*R;from++)///枚举每条路径的起点 if(net[from/R][from%R]=='.') for(int dir=0;dir<8;dir++){///枚举每条路径的方向; int len=0; int r=from/R;///起点的行数 int c=from%R;///起点的列数 while(r+dr[dir]>=0 && r+dr[dir]<R && c+dc[dir]>=0 && c+dc[dir]<R && net[ r+dr[dir] ][ c+dc[dir] ]=='.'){ len++; r=r+dr[dir]; c=c+dc[dir]; } int to=r*R+c; if(to!=from){ paths.push_back(Path(from,to,len+1,dir) );ans=max(ans,len+1);} } int size=paths.size(); sort(paths.begin(),paths.end()); for(int i=0;i<size;i++){ if(!binary_search(paths.begin(),paths.end(),paths[i]))continue; int low=lower_bound(paths.begin(),paths.end(),paths[i])-paths.begin(); int high=upper_bound(paths.begin(),paths.end(),paths[i])-paths.begin()-1; for(int j=low;j<high;j++)///道路是有向的 if(is_rec(paths[i].dir,paths[j].dir)){ ans=max(ans,paths[i].len+paths[j].len-1); } } cout<<ans<<endl; } return 0;}
0 0
- HDOJ 5024 Wang Xifeng's Little Plot
- 【DP】 HDOJ 5024 Wang Xifeng's Little Plot
- hdoj 5024 Wang Xifeng's Little Plot 【DFS暴力】
- HDU - 5024 Wang Xifeng's Little Plot
- hdu 5024 Wang Xifeng's Little Plot
- HDU -- 5024 Wang Xifeng's Little Plot
- HDU 5024 Wang Xifeng's Little Plot
- hdu 5024 Wang Xifeng's Little Plot
- HDU 5024 Wang Xifeng's Little Plot
- HDU 5024 Wang Xifeng's Little Plot (bfs)
- hdu 5024 Wang Xifeng's Little Plot【暴力dfs,剪枝】
- Wang Xifeng's Little Plot (poj 5024 DFS)
- HDU 5024 Wang Xifeng's Little Plot (搜索)
- hdu 5024 Wang Xifeng's Little Plot (dfs+暴力)
- hdu 5024 Wang Xifeng's Little Plot(搜索:遍历)
- HDU 5024 Wang Xifeng's Little Plot (搜索)
- Wang Xifeng's Little Plot - HDU 5024 搜索
- hdu 5024 Wang Xifeng's Little Plot(递推)
- LeetCode -- Median of Two Sorted Arrays
- 一阶二阶电路滤波器的软件方式实现
- JAVA输入输出总结
- 一个字符串过滤程序
- HDOJ 5023 A Corrupt Mayor's Performance Art
- HDOJ 5024 Wang Xifeng's Little Plot
- cf 24 Game (观察+.. 想一想)
- 人生感想
- 2信号处理之:信号产生原因,进程处理信号行为,信号集处理函数,PCB的信号集,sigprocmask()和sigpending(),信号捕捉设定,sigaction,C标准库信号处理函数,可重入函数,
- Java解析HTML标签
- BC D Revenge of kNN II hdu 5021
- Oracle数据库体系结构总结
- http 配置的解析
- 3信号处理之:避免异步IO的类型,SIGCHLD信号处理