当前位置: 首页 > news >正文

Mirror Maze 镜面反射

题目描述

You are given a grid of R rows (numbered from 1 to R from north to south) and C columns (numbered from 1 to C from west to east). Every cell in this grid is a square of the same size. The cell located at row r and column c is denoted as (r, c) . Each cell can either be empty or have a mirror in one of the cell’s diagonals.
Each mirror is represented by a line segment. The mirror is type 1 if it is positioned diagonally from the southwest corner to the northeast corner of the cell, or type 2 for the other diagonal.
These mirrors follow the law of refl ection, that is, the angle of refl ection equals the angle of incidence.
Formally, for type 1 mirror, if a beam of light comes from the north, south, west, or east of the cell, then it will be refl ected to the west, east, north, and south of the cell, respectively. Similarly, for type 2 mirror, if a beam of light comes from the north, south, west, or east of the cell, then it will be refl ected to the east, west,south, and north of the cell, respectively.


You want to put a laser from outside the grid such that all mirrors are hit by the laser beam. There are 2 · (R + C) possible locations to put the laser:
• from the north side of the grid at column c , for 1 ≤ c ≤ C , shooting a laser beam to the south;
• from the south side of the grid at column c , for 1 ≤ c ≤ C , shooting a laser beam to the north;
• from the east side of the grid at row r , for 1 ≤ r ≤ R , shooting a laser beam to the west; and
• from the west side of the grid at row r , for 1 ≤ r ≤ R , shooting a laser beam to the east.

Determine all possible locations for the laser such that all mirrors are hit by the laser beam.

输入

The first line consists of two integers R C ( 1 ≤ R, C ≤ 200 ).
Each of the next R lines consists of a string S r of length C . The cth character of string S r represents cell (r, c) . Each character can either be . if the cell is empty, / if the cell has type 1 mirror, or \ if the cell has type 2 mirror. There is at least one mirror in the grid.

输出

Output a single integer representing the number of possible locations for the laser such that all mirrors are hit by the laser beam. Denote this number as k .
If k > 0 , then output k space-separated strings representing the location of the laser. Each string consists of a character followed without any space by an integer. The character represents the side of the grid, which could be N , S , E , or W if you put the laser on the north, south, east, or west side of the grid,
respectively. The integer represents the row/column number. You can output the strings in any order.

样例输入

复制

【样例1】
4 4
.//.
.\\.
.\/.
....
【样例2】
4 6
./..\.
.\...\
./../\
......
【样例3】
4 4
....
./\.
.\/.
....
样例输出

复制

【样例1】
2
N3 W2
【样例2】
2
E3 S2
【样例3】
0
提示

Explanation for the sample input/output #1
The following illustration shows one of the solutions of this sample.


Explanation for the sample input/output #2
The following illustration shows one of the solutions of this sample.

ans保存的时候不能用 ' 1 ' + i 保存。。。。这个只适用于个位数

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;int r,c,cnt[209][209];
int fx[]{-1,0,1,0},fy[]{0,1,0,-1};
char mirror[209][209];int refl(int x,int y,int p)
{if(mirror[x][y]=='/'){if(p==0)return 1;if(p==1)return 0;if(p==2)return 3;return 2;}if(p==0)return 3;if(p==1)return 2;if(p==2)return 1;return 0;
}int check()
{for(int i=0;i<r;++i){for(int j=0;j<c;++j){if(mirror[i][j]!='.'&&!cnt[i][j])return 0;}}return 1;
}void go(int x,int y,int p)
{	memset(cnt,0,sizeof(cnt));while(true){if(x<0||x>=r||y<0||y>=c)return;		if(mirror[x][y]!='.')cnt[x][y]=1,p=refl(x,y,p);x+=fx[p],y+=fy[p];}
}int main()
{cin>>r>>c;for(int i=0;i<r;++i){for(int j=0;j<c;++j)cin>>mirror[i][j];}vector<string>ans;for(int i=0;i<c;++i){go(0,i,2);if(check())ans.push_back("N"+to_string(1+i));}for(int i=0;i<c;++i){go(r-1,i,0);if(check())ans.push_back("S"+to_string(1+i));}for(int i=0;i<r;++i){go(i,0,1);if(check())ans.push_back("W"+to_string(1+i));}for(int i=0;i<r;++i){go(i,c-1,3);if(check())ans.push_back("E"+to_string(1+i));}cout<<ans.size()<<'\n';if(!ans.empty()){for(auto i:ans)cout<<i<<" ";}return 0;
}

http://www.dtcms.com/a/394524.html

相关文章:

  • 一个案例弄懂nfs
  • 在飞牛NAS使用Lucky做动态解析到域名?
  • 多实例 MySQL 部署
  • 使用批处理脚本快速切换 Claude API 实现多平台环境配置
  • SkyDiffusion:用 BEV 视角打开街景→航拍图像合成新范式
  • 免费下载适用于 Windows PC 的 Pixologic Zbrush 2026
  • 10.eNSP下载及安装教程(2025年9月21日)
  • Qt 实战 之 打包部署
  • QT-文件
  • 2001-2022年全国地级市高铁开通数据
  • TenstoRT加速YOLOv11——C++端加速
  • 面试技巧第三篇:嵌入式操作系统基础考点:任务、调度和中断
  • 简单使用Vanna
  • 【面板数据】各省环境保护支出统计数据集(2007-2023年)
  • 无需格式转换!FileOptimizer将文件体积压至极致的软件
  • 【论文速递】2025年第17周(Apr-20-26)(Robotics/Embodied AI/LLM)
  • Spring Framework 入门:传统 XML 配置启动方式详解
  • 构建AI智能体:四十、K-Means++与RAG的融合创新:智能聚类与检索增强生成的深度应用
  • Python 中,判断元素是否存在于列表(list)和判断键是否存在于字典(dict)
  • 如何在 Windows 上恢复已删除/未保存的 PowerPoint 文件 - 4 种快速方法
  • 【含文档+PPT+源码】基于过滤协同算法的城市旅游网站的设计与实现
  • week 2
  • Core Animation基础
  • OpenVLC解析
  • 【AI论文】ScaleCUA:借助跨平台数据扩展开源计算机使用代理(系统/工具)规模
  • NW951NW916美光固态闪存NW926NW927
  • Python 如何优雅处理 100GB 数据集——实战案例
  • 快速学习Python(有其他语言基础)
  • 全网首发! Nvidia Jetson Thor 128GB DK 刷机与测评(六)常用功能测评 pi0、pi0.5 环境部署
  • git环境操作指南