hdu5024-Wang Xifeng's Little Plot
此题一开始用暴力做,后来发现斜着走的时候其实暴力不太好写,于是改用搜索写了
1 #include <iostream> 2 #include <stdio.h> 3 #include <memory.h> 4 using namespace std; 5 6 char a[110][110]= {0}; 7 int down[110][110]= {0}; 8 int up[110][110]= {0}; 9 10 int cnt[110][110][4]= {0}; 11 int n; 12 int dx[4]= {-1,1,-1, 1}; 13 int dy[4]= {-1,1, 1,-1}; 14 int dfs(int curx,int cury,int num) 15 { 16 if(curx<0 || cury<0 || curx>=n || cury>=n) 17 return 0; 18 int &ans=cnt[curx][cury][num]; 19 if(a[curx][cury]=='#') 20 return ans=0; 21 return ans=1+dfs(curx+dx[num],cury+dy[num],num); 22 } 23 24 25 int getMax() 26 { 27 int ans=0; 28 for(int i=0; i<n; i++) 29 for(int j=0; j<n; j++) 30 { 31 ans=max(ans,down[i][j]+up[i][j]-1); 32 } 33 return ans; 34 } 35 36 int main() 37 { 38 freopen("in.txt","r",stdin); 39 40 while(scanf("%d",&n),n) 41 { 42 memset(down,0,sizeof down); 43 memset(up,0,sizeof up); 44 memset(cnt,0,sizeof cnt); 45 for(int i=0; i<n; i++) 46 scanf("%s",a[i]); 47 48 for(int i=0; i<n; i++) 49 for(int j=0; j<n; j++) 50 { 51 if(a[i][j]=='#') 52 { 53 up[i][j]=down[i][j]=0; 54 55 } 56 else 57 { 58 up[i][j]=down[i][j]=1; 59 if(i!=0) 60 up[i][j]=up[i-1][j]+1; 61 if(j!=0) 62 down[i][j]=down[i][j-1]+1; 63 } 64 } 65 66 int ans=0; 67 ans=max(ans,getMax()); 68 69 memset(down,0,sizeof down); 70 memset(up,0,sizeof up); 71 for(int i=n-1; i>=0; i--) 72 for(int j=n-1; j>=0; j--) 73 { 74 if(a[i][j]=='#') 75 { 76 up[i][j]=down[i][j]=0; 77 } 78 else 79 { 80 up[i][j]=down[i][j]=1; 81 if(i!=n-1) 82 up[i][j]=up[i+1][j]+1; 83 if(j!=n-1) 84 down[i][j]=down[i][j+1]+1; 85 } 86 } 87 88 ans=max(ans,getMax()); 89 90 //--------------------------- 91 memset(down,0,sizeof down); 92 memset(up,0,sizeof up); 93 for(int i=0; i<n; i++) 94 for(int j=n-1; j>=0; j--) 95 { 96 if(a[i][j]=='#') 97 { 98 up[i][j]=down[i][j]=0; 99 } 100 else 101 { 102 up[i][j]=down[i][j]=1; 103 if(i!=0) 104 up[i][j]=up[i-1][j]+1; 105 if(j!=n-1) 106 down[i][j]=down[i][j+1]+1; 107 } 108 } 109 110 ans=max(ans,getMax()); 111 //------------------------------- 112 memset(down,0,sizeof down); 113 memset(up,0,sizeof up); 114 for(int i=n-1; i>=0; i--) 115 for(int j=0; j<n; j++) 116 { 117 if(a[i][j]=='#') 118 { 119 up[i][j]=down[i][j]=0; 120 } 121 else 122 { 123 up[i][j]=down[i][j]=1; 124 if(i!=n-1) 125 up[i][j]=up[i+1][j]+1; 126 if(j!=0) 127 down[i][j]=down[i][j-1]+1; 128 } 129 } 130 131 ans=max(ans,getMax()); 132 //-------------------------------------------------- 133 134 for(int i=0; i<n; i++) 135 for(int j=0; j<n; j++) 136 { 137 for(int num=0; num<4; num++) 138 { 139 dfs(i,j,num); 140 } 141 } 142 143 for(int i=0; i<n; i++) 144 for(int j=0; j<n; j++) 145 { 146 ans=max(ans,cnt[i][j][0]+cnt[i][j][2]-1); 147 ans=max(ans,cnt[i][j][0]+cnt[i][j][3]-1); 148 ans=max(ans,cnt[i][j][1]+cnt[i][j][3]-1); 149 ans=max(ans,cnt[i][j][1]+cnt[i][j][2]-1); 150 } 151 152 cout<<ans<<endl; 153 } 154 return 0; 155 }
转载于:https://www.cnblogs.com/oneshot/p/3983502.html
hdu5024-Wang Xifeng's Little Plot相关推荐
- Hdu-5024 Wang Xifeng's Little Plot(记忆化搜索)
Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- Wang Xifeng's Little Plot (poj 5024 DFS)
Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- 2014 ACM/ICPC Asia Regional Guangzhou Online C题Wang Xifeng's Little Plot(dfs)
Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- 2014 ACM/ICPC Asia Regional Guangzhou Online Wang Xifeng's Little Plot HDU5024
一道好枚举+模拟题目.转换思维视角 这道题是我做的,规模不大N<=100,以为正常DFS搜索,于是傻乎乎的写了起来.各种条件限制模拟过程 但仔细一分析发现对每个点进行全部八个方向的遍历100X1 ...
- 2014 网选 5024 Wang Xifeng's Little Plot
题意:从任意一个任意一个可走的点开始找一个最长的路,这条路如果有转弯的话, 那么必须是 90度,或者没有转弯! 思路: 首先用dfs将所有可走点开始的 8 个方向上的线段的最长长度求出来 ! step ...
- 2014广州网络赛1003||hdu 5024 搜索
http://acm.hdu.edu.cn/showproblem.php?pid=5024 Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (J ...
- Python的知识点 plt.plot()函数细节
20201228 lw 是line width 线的宽度 1.plt.plot(x,y,format_string,**kwargs) 转自点击打开链接 x轴数据,y轴数据,format_strin ...
- pycharm中报错:Error: failed to send plot to http://127.0.0.1:63342
pycharm中报错:Error: failed to send plot to http://127.0.0.1:63342 import matplotlib.pyplot as plt impo ...
- matlab数据可视化总结,机器学习----Matlab数据可视化总结(plot篇)
前言 通过资料的整理,使用Matlab语言的plot函数将数据可视化,plota函数也是一个比较常用的二维绘图函数,针对向量或矩阵.如果你也想试一试,初学者记得使用clf.close或close al ...
最新文章
- 利用OpenCV 基于Inception模型图像分类
- R语言使用ggplot2包使用geom_violin函数绘制分组小提琴图(配置填充色调色板、brewer调色板、灰度比例)实战
- R语言tidyr包separate()函数实战详解:一列裂变为多列
- 倍福ads通讯软件_软件定义汽车“性感”吗?东软睿驰有自己的答案
- 'yii\base\InvalidRouteException' with message 'Unable to resolve the request site/error.'
- Sprint第二个冲刺(第八天)
- SGU 109 Magic of David Copperfield II
- java12小时制的时间转换为24小时制
- 推荐!计算机视觉最适合入门的 8 本教程,算法与实战兼备
- 构造方法,this,super关键字
- webLogic11g部署war包问题解决方案(转)
- ORA-00980与PL/SQL程序编译出错
- Easyexcel异常处理:getOutputStream() has already been called for this response
- java中else语句有错_java 菜鸟 If else有错误
- python函数返回多个值_python函数返回多个值的示例方法
- java开发大全、系列文章、精品教程
- 【2019年天梯赛L2-029】特立独行的幸福(模拟)
- 大漠插件7.2209
- 讲讲MS08067红队培训班中的“毕业实战对抗”环节 + 视频
- TI 蓝牙4.0芯片 cc2540
热门文章
- 网络行业协会责令十大流氓软件整改(继续踩他们一脚)
- 【推荐】本周值得关注的将开源论文,包含分类、分割、人脸、目标检测、ReID等...
- ResNet压缩20倍,Facebook提出新型无监督模型压缩量化方法
- 2019全国智能机器人与SLAM技术博士生论坛第二轮通知
- ICCV 2019丨微软亚研院精选论文解读
- StegaStamp:加州大学伯克利分校开源神奇的照片隐写术,打印的照片能当二维码用...
- 零基础学习Python文本处理
- 带你自学Python系列(一):变量和简单数据类型(附思维导图)
- 大数据预测实战-随机森林预测实战(四)-模型微调
- NLP基础|中英文词向量评测理论与实践