当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6771:It's All Squares

题目描述
One day when Little Q woke up, he found himself being inside a 2D pixel world. The world is a grid with $n\times m$ square cells. Little Q can only walk along the side of these cells, which means he can stay at a point $(x,y)$ if and only if $0\leq x\leq n$ and $0\leq y\leq m$, where $x$ and $y$ are all integers. There is a number written at the center of each cell, number $w_{i,j}$ ($1\leq i\leq n,1\leq j\leq m$) is written at the point $(i-0.5,j-0.5)$.

Little Q had no idea about how to escape from the pixel world, so he started wandering. You will be given $q$ queries, each query consists of two integers $(x,y)$ and a string $S$, denoting the route of Little Q. Initially, Little Q will stand at $(x,y)$, then he will do $|S|$ steps of movements $S_1,S_2,\dots,S_{|S|}$ one by one. Here is what he will do for each type of movement:

· "$\texttt{L}$" : Move from $(x,y)$ to $(x-1,y)$.

· "$\texttt{R}$" : Move from $(x,y)$ to $(x+1,y)$.

· "$\texttt{D}$" : Move from $(x,y)$ to $(x,y-1)$.

· "$\texttt{U}$" : Move from $(x,y)$ to $(x,y+1)$.

It is guaranteed that Little Q will never walk outside of the pixel world, and the route will form a simple polygon. For each query, please tell Little Q how many distinct numbers there are inside the polygon formed by the route.

Fortunately, after solving this problem, Little Q woke up on his bed. The pixel world had just been a dream!
输入解释
The first line of the input contains a single integer $T$ ($1 \leq T \leq 10$), the number of test cases.

For each case, the first line of the input contains three integers $n,m$ and $q$ ($1 \leq n,m \leq 400$, $1\leq q\leq 200\,000$), denoting the size of the pixel world and the number of queries.

Each of the following $n$ lines contains $m$ integers, the $i$-th line contains $m$ integers $w_{i,1},w_{i,2},\dots,w_{i,m}$ ($1\leq w_{i,j}\leq n\times m$), denoting the number written in each cell.

Each of the following $q$ lines contains two integers $x,y$ ($0\leq x\leq n$, $0\leq y\leq m$) and a non-empty string $S$ ($S_i\in\{\texttt{L},\texttt{R},\texttt{D},\texttt{U}\}$), denoting each query.

It is guaranteed that $\sum |S|\leq 4\,000\,000$.
输出解释
For each query, output a single line containing an integer, the number of distinct numbers inside the polygon.
输入样例
1
3 3 2
1 2 3
1 1 2
7 8 9
0 0 RRRUUULLLDDD
0 0 RRUULLDD
输出样例
6
2
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6771

最后修改于 2020-10-25T23:34:14+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/4000MS(Java/Others) 524288/524288K(Java/Others)