题意翻译

有一个n*m的格子图,其中有一些是黑色的,另一些为白色。

从某个白色格子的中心点向左上(NW),左下(SW),右上(NE),右下(SE)四个方向中的一个发出一束光线,若光线碰到黑色格子或者墙壁(即边界)会反射。反射情况如图所示:

我们不难发现,光线能穿过的格子总数是可以算出的。假如光线经过了某个格子的中心,则称光线经过了这个格子。求光线经过的格子总数。

由于答案可能很大,请使用long long的C++选手注意:请勿使用%lld,推荐cout或者%I64d

题目描述

Imagine an n×mn×m grid with some blocked cells. The top left cell in the grid has coordinates (1,1)(1,1) and the bottom right cell has coordinates (n,m)(n,m) . There are kk blocked cells in the grid and others are empty. You flash a laser beam from the center of an empty cell (x_{s},y_{s})(xs​,ys​) in one of the diagonal directions (i.e. north-east, north-west, south-east or south-west). If the beam hits a blocked cell or the border of the grid it will reflect. The behavior of the beam reflection in different situations is depicted in the figure below.

After a while the beam enters an infinite cycle. Count the number of empty cells that the beam goes through at least once. We consider that the beam goes through cell if it goes through its center.

输入输出格式

输入格式:

The first line of the input contains three integers nn , mm and kk (1<=n,m<=105,0<=k<=105) . Each of the next kk lines contains two integers(1<=xi​<=n,1<=yi​<=m) indicating the position of the ii -th blocked cell.

The last line contains(1<=xs​<=n,1<=ys​<=m) and the flash direction which is equal to "NE", "NW", "SE" or "SW". These strings denote directions (-1,1)(−1,1) , (-1,-1)(−1,−1) , (1,1)(1,1) , (1,-1)(1,−1) .

It's guaranteed that no two blocked cells have the same coordinates.

输出格式:

In the only line of the output print the number of empty cells that the beam goes through at least once.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

输入输出样例

输入样例#1:
3 3 0
1 2 SW
输出样例#1:

6

输入样例#2:

7 5 3

3 3 4

3 5 3

2 1 SE

输出样例#2:

14

题目分析

恶心啊。

根据惯例我们先列一下需要考虑的问题:
1.四种方块的反射状态

2.在一定时间后光线会重复循环,此时终止

3.数据范围带来的不能用邻接矩阵存图的麻烦

4.坐标从0开始很不好处理

写吧,细节解决方案看代码

Code

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<vector>
  4. using namespace std;
  5.  
  6. const int MAXN = 1e5 + ;
  7. const int INF = 0x3f3f3f3f;
  8.  
  9. int n,m,k;
  10. int sx,sy,sd;
  11. vector<int> block[MAXN];
  12. string S;
  13. bool flag;
  14.  
  15. void add(int x,int y) {
  16. block[x].push_back(y);
  17. return;
  18. }
  19.  
  20. void scan() {
  21. scanf("%d%d",&n,&m,&k);
  22. scanf("%d%d%s",&sx,&sy,&S);
  23. if(S == "NW") sd = ;
  24. else if(S == "NE") sd = ;
  25. else if(S == "SW") sd = ;
  26. else if(S == "SE") sd = ;
  27. int x,y;
  28. for(int i = ;i <= k;i++) {
  29. scanf("%d%d",&x,&y);
  30. add(x,y);
  31. }
  32. for(int i = ;i <= n;i++) add(i,),add(i,m + );
  33. for(int j = ;j <= n;j++) add(,j),add(n + ,j);
  34. add(,);add(n + ,m + );
  35. return;
  36. }
  37.  
  38. void dir_judge(int x,int y,int &d) {
  39. if(d == ) {
  40. if(!getblock(x-,y-)) return;
  41. else {
  42. int opt = getblock(x,y-) - getblock(x-,y);
  43. if(opt == ) d = ;
  44. else if(opt == ) d = ;
  45. else if(opt == -) d = ;
  46. }
  47. } else if(d == ) {
  48. if(!getblock(x-,y+)) return;
  49. else {
  50. int opt = getblock(x-,y) - getblock(x,y+);
  51. if(opt == ) d = ;
  52. else if(opt == ) d = ;
  53. else if(opt == -) d = ;
  54. }
  55. } else if(d == ) {
  56. if(!getblock(x+,y-)) return;
  57. else {
  58. int opt = getblock(x,y-) - getblock(x+,y);
  59. if(opt == ) d = ;
  60. else if(opt == ) d = ;
  61. else if(opt == -) d = ;
  62. }
  63. } else if(d == ) {
  64. if(!getblock(x+,y+)) return;
  65. else {
  66. int opt = getblock(x-,y) - getblock(x,y-);
  67. if(opt == ) d = ;
  68. else if(opt == ) d = ;
  69. else if(opt == -) d = ;
  70. }
  71. }
  72. }
  73. /*
  74. NW 1 NE 2
  75.  
  76. SW 3 SE 4
  77. */
  78.  
  79. void start() {
  80. int x = sx,y = sy,d = sd;
  81. while(!flag) {
  82. dir_judge(x,y,d);
  83. }
  84. }
  85.  
  86. main() {
  87. scan();
  88. start();
  89. }

[CodeForces] 274E Mirror Room的更多相关文章

  1. [Codeforces 274E]:Mirror Room(模拟)

    题目传送门 题目描述 有一个$n\times m$的格子图,其中有一些是黑色的,另一些为白色.从某个白色格子的中心点向左上($NW$),左下($SW$),右上($NE$),右下($SE$)四个方向中的 ...

  2. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror) in codeforces(codeforces730)

    A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ ...

  3. [codeforces 241]C. Mirror Box

    [codeforces 241]C. Mirror Box 试题描述 Mirror Box is a name of a popular game in the Iranian National Am ...

  4. Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!

    VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...

  5. Codeforces Bubble Cup 8 - Finals [Online Mirror] B. Bribes lca

    题目链接: http://codeforces.com/contest/575/problem/B 题解: 把链u,v拆成u,lca(u,v)和v,lca(u,v)(v,lca(u,v)是倒过来的). ...

  6. Codeforces Bubble Cup 8 - Finals [Online Mirror]H. Bots 数学

    H. Bots Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/H Desc ...

  7. Codeforces Bubble Cup 8 - Finals [Online Mirror] D. Tablecity 数学题

    D. Tablecity Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/D ...

  8. Codeforces Bubble Cup 8 - Finals [Online Mirror] F. Bulbo DP

    F. Bulbo Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/F Des ...

  9. Codeforces 1182D Complete Mirror [树哈希]

    Codeforces 中考考完之后第一个AC,纪念一下qwq 思路 简单理解一下题之后就可以发现其实就是要求一个点,使得把它提为根之后整棵树显得非常对称. 很容易想到树哈希来判结构是否相同,而且由于只 ...

随机推荐

  1. iOS开发- SceneKit

    打开你的Xcode 6然后新建一个项目,选择iOS/Application/Game模板然后点击Next. 将项目命名为QuickStart,选择开发语言为Swift,然后游戏选用的平台技术选择为Sc ...

  2. 【Aladdin Unity3D Shader编程】之二 光照模型(一)

    光照模型 光照模型就是一个公式,使用这个公式来计算在某个点的光照效果. 在标准光照模型里面,我们把进入摄像机的光分为下面四个部分: 自发光 类似生活中的萤火虫等自己能够发光 高光反射 类似生活中的镜子 ...

  3. XHR ajax

    谷歌搜索xhr site:cnblogs.com https://www.cnblogs.com/xiaohuochai/p/6036475.html 在Chrome的network监视中,类型为XH ...

  4. XAML实例教程系列 - 命名空间(NameSpace) 三

    XAML实例教程系列 - 命名空间(NameSpace) 2012-05-28 14:14 by jv9, 2205 阅读, 10 评论, 收藏, 编辑 上一篇曾提及XAML中,每个对象元素的声明是对 ...

  5. Visual Studio AI

    Visual Studio 完全AI手册 - 从0开始配置环境 https://www.cnblogs.com/ms-uap/p/9123033.html 零.前提条件 一台能联网的电脑,使用win1 ...

  6. tinymce 富文本编辑器 编写资料

    tinymce官方文档: 粘贴图片插件 博客搬运地址 使用Blob获取图片并二进制显示实例页面 tinymce自动调整插件 是时候掌握一个富文本编辑器了——TinyMCE(1) XMLHttpRequ ...

  7. 【WIP】客户端JavaScript DOM

    创建: 2017/10/12 初步完成: 2017/10/15   更新: 2017/10/14 标题加上[WIP],继续完成     [TODO] 补充暂略的, 搜[略]  DOM树  概要  基本 ...

  8. ural 1012. K-based Numbers. Version 2(大数dp)

    和1009相同,只是n达到了180位,可以模拟大数加和大数乘,这里用的java中的大数. import java.math.BigInteger; import java.util.Scanner; ...

  9. bzoj1877 晨跑(费用流)

    1877: [SDOI2009]晨跑 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 2138  Solved: 1145 Description Elax ...

  10. 哈夫曼编码译码系统(c/c++)

    哈夫曼编码译码系统的实现,主要包含三部分: 1.创建哈夫曼树 2.编码函数 3.译码函数 编写代码时为了方便,在这里混用了c++的输入输出流.主体用c语言实现. 下面时代码部分: 1.头文件,以及储存 ...