SSL-ZYC 反射
2018-01-29 14:00
141 查看
题目大意:
在一个长方形的区域里,每个位置都有一面镜子,请问从长方形外任意一点照射,光最多可以被反射几次?
思路:
这道题个人认为是一道比较难的暴力模拟,我们用s[i][j]来表示第i行j列的镜子的放置情况,f表示镜子反射的方向,以上,下,左,右的顺序来尝试从每个位置开始照射,最终输出正确结果。
这道题只需多注意些细节就行了。
代码:
在一个长方形的区域里,每个位置都有一面镜子,请问从长方形外任意一点照射,光最多可以被反射几次?
思路:
这道题个人认为是一道比较难的暴力模拟,我们用s[i][j]来表示第i行j列的镜子的放置情况,f表示镜子反射的方向,以上,下,左,右的顺序来尝试从每个位置开始照射,最终输出正确结果。
这道题只需多注意些细节就行了。
代码:
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; char s[1001][1001]; int n,m,a[1001][1001],f,sum,maxn; int main() { freopen("mirror.in","r",stdin); freopen("mirror.out","w",stdout); scanf("%d%d",&n,&m); getchar(); for (int i=1;i<=n;i++,getchar()) { for (int j=1;j<=m;j++) s[i][j]=getchar(); } for (int i=1;i<=3;i+=2) //从上和下寻找 for (int j=1;j<=m;j++) { f=i; sum=0; int x,y=j; if (i==1) x=1; else x=n; while (x>=1&&y>=1&&x<=n&&y<=m) { if (s[x][y]=='/'&&f==1&&y>=1) y--,f=4; else if (s[x][y]=='/'&&f==2&&x>=1) x--,f=3; else if (s[x][y]=='/'&&f==3&&y<=m) y++,f=2; else if (s[x][y]=='/'&&f==4&&x<=n) x++,f=1; else if (s[x][y]!='/'&&f==1&&y<=m) y++,f=2; else if (s[x][y]!='/'&&f==2&&x<=n) x++,f=1; else if (s[x][y]!='/'&&f==3&&y>=1) y--,f=4; else if (s[x][y]!='/'&&f==4&&x>=1) x--,f=3; //更改位置及方向 sum++; } maxn=max(sum,maxn); } for (int j=2;j<=4;j+=2) //从左和右寻找 for (int i=1;i<=n;i++) { f=j; sum=0; int x=i,y; if (j==2) y=1; else y=m; a[i][j]=1; while (x>=1&&y>=1&&x<=n&&y<=m) { if (s[x][y]=='/'&&f==1&&y>=1) y--,f=4; else if (s[x][y]=='/'&&f==2&&x>=1) x--,f=3; else if (s[x][y]=='/'&&f==3&&y<=m) y++,f=2; else if (s[x][y]=='/'&&f==4&&x<=n) x++,f=1; else if (s[x][y]!='/'&&f==1&&y<=m) y++,f=2; else if (s[x][y]!='/'&&f==2&&x<=n) x++,f=1; else if (s[x][y]!='/'&&f==3&&y>=1) y--,f=4; else if (s[x][y]!='/'&&f==4&&x>=1) x--,f=3; //更改位置及方向 sum++; } maxn=max(sum,maxn); } printf("%d",maxn); }
相关文章推荐
- SSL-ZYC 作业
- SSL-ZYC 懒惰的奶牛①
- SSL-ZYC 奶牛的声音
- SSL-ZYC 最小步数
- SSL-ZYC 2547 圆环
- SSL-ZYC 2408 比萨
- SSL-ZYC 方案数
- SSL-ZYC 1500 最短路上的统计
- SSL-ZYC 1455 电子老鼠闯迷宫
- SSL-ZYC 1618 剑鱼行动
- SSL-ZYC 危险系数
- SSL-ZYC 愤怒的牛
- SSL-ZYC 2324 细胞问题
- SSL-ZYC 1760 商店选址问题
- SSL-ZYC 道路阻塞
- SSL-ZYC 旅行
- SSL-ZYC 1763 观光旅游
- SSL-ZYC 1764 最小生成树Ⅱ
- SSL-ZYC 1454 找石油
- SSL-ZYC 前缀转后缀