题意翻译

有一个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

#include<iostream>
#include<cstdio>
#include<vector>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f; int n,m,k;
int sx,sy,sd;
vector<int> block[MAXN];
string S;
bool flag; void add(int x,int y) {
block[x].push_back(y);
return;
} void scan() {
scanf("%d%d",&n,&m,&k);
scanf("%d%d%s",&sx,&sy,&S);
if(S == "NW") sd = ;
else if(S == "NE") sd = ;
else if(S == "SW") sd = ;
else if(S == "SE") sd = ;
int x,y;
for(int i = ;i <= k;i++) {
scanf("%d%d",&x,&y);
add(x,y);
}
for(int i = ;i <= n;i++) add(i,),add(i,m + );
for(int j = ;j <= n;j++) add(,j),add(n + ,j);
add(,);add(n + ,m + );
return;
} void dir_judge(int x,int y,int &d) {
if(d == ) {
if(!getblock(x-,y-)) return;
else {
int opt = getblock(x,y-) - getblock(x-,y);
if(opt == ) d = ;
else if(opt == ) d = ;
else if(opt == -) d = ;
}
} else if(d == ) {
if(!getblock(x-,y+)) return;
else {
int opt = getblock(x-,y) - getblock(x,y+);
if(opt == ) d = ;
else if(opt == ) d = ;
else if(opt == -) d = ;
}
} else if(d == ) {
if(!getblock(x+,y-)) return;
else {
int opt = getblock(x,y-) - getblock(x+,y);
if(opt == ) d = ;
else if(opt == ) d = ;
else if(opt == -) d = ;
}
} else if(d == ) {
if(!getblock(x+,y+)) return;
else {
int opt = getblock(x-,y) - getblock(x,y-);
if(opt == ) d = ;
else if(opt == ) d = ;
else if(opt == -) d = ;
}
}
}
/*
NW 1 NE 2 SW 3 SE 4
*/ void start() {
int x = sx,y = sy,d = sd;
while(!flag) {
dir_judge(x,y,d);
}
} main() {
scan();
start();
}

[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. 利用jQuery Ajax技术实现每隔5秒向某页面传值

    有时候我们须要每隔一段时间向某页面传值,比方说聊天室,每隔几秒就像数据库处理页面传值并取回,然后显示在聊天窗体.又或者是每隔一段时间就查询用户最后发言时间到如今是否间隔2分钟.假设是则将用户退出. 这 ...

  2. 约瑟夫环问题(猴子选大王)PHP版

    约瑟夫斯问题问题有时候也被描述成猴子选大王问题,题目如下.(最后会贴上约瑟夫问题的来历) 一群猴子排成一圈,按1,2,…,n依次编号. 然后从第1只开始数,数到第m只,把它踢出圈,从它后面再开始数,再 ...

  3. 【bzoj1821】[JSOI2010]Group 部落划分 Group

    题目大意:要求把n个点分成m块,使得每一块之间的距离的最小值最大 n^2枚举所有点之间距离 然后sort一下 并查集维护连通关系 一开始e[]开MAXN然后WA了测了4ms,然后开MAXN<&l ...

  4. YTU 2723: 默认参数--求圆的面积

    2723: 默认参数--求圆的面积 时间限制: 1 Sec  内存限制: 128 MB 提交: 206  解决: 150 题目描述 根据半径r求圆的面积, 如果不指定小数位数,输出结果默认保留两位小数 ...

  5. JSP-Runoob:JSP 点击量统计

    ylbtech-JSP-Runoob:JSP 点击量统计 1.返回顶部 1. JSP 点击量统计 有时候我们需要知道某个页面被访问的次数,这时我们就需要在页面上添加页面统计器,页面访问的统计一般在用户 ...

  6. 【Hibernate总结系列】使用举例

    本节讲述如何使用Hibernate实现记录的增.删.改和查功能. 1 查询 在Hibernate中使用查询时,一般使用Hql查询语句. HQL(Hibernate Query Language),即H ...

  7. codevs1690 开关灯(线段树)

    1690 开关灯 USACO  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond     题目描述 Description YYX家门前的街上有N(2< ...

  8. poj1988Cute Stacking

    题目大意:有几个stack,初始里面有一个cube.支持两种操作:1.move x y: 将x所在的stack移动到y所在stack的顶部.2.count x:数在x所在stack中,在x之下的cub ...

  9. viewDidUnload,viewDidLoad,viewWillAppear,viewWillDisappear的作用以及区别

    viewDidLoad:在视图加载后被调用 viewWillAppear:视图即将可见时调用.默认情况下不执行任何操作 viewDidAppear: 视图已完全过渡到屏幕上时调用 viewWillDi ...

  10. ex41习题 41: 来自 Percal 25 号行星的哥顿人(Gothons)

    ex41习题 41: 来自 Percal 25 号行星的哥顿人(Gothons) 学习到本题卡住了,遇到一点费解的地方,mark一下.本题主要是介绍函数在字典这种数据类型中的应用,本实验在python ...