QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#20979. 陷入轍跡

Statistics

Farmer John 最近擴大了農場,在乳牛眼中,現在它幾乎無限大!乳牛將放牧區看成由正方形「格子」組成的無限二維網格,每格都長滿美味的草(可以將每格想成無限棋盤上的一格)。他的 $N$ 頭乳牛($1\le N\le 50$)各從一個不同格子出發,有的朝北,有的朝東。

每小時,每頭乳牛進行以下兩種行為之一:

  • 若目前格子的草已經被另一頭乳牛吃掉,就停下。
  • 吃掉目前格子的所有草,並沿面對的方向前進一格。

因此,隨著時間推移,每頭乳牛身後都會留下由空格子組成的荒蕪「轍跡」。

若兩頭乳牛在同一次移動中進入同一個有草的格子,牠們共用該格,並在下一小時繼續沿各自的方向移動。

請確定每頭乳牛吃掉的草量。有些乳牛永不停下,因此會吃掉無限多的草。

輸入格式

輸入的第一行包含 $N$。接下來的 $N$ 行各描述一頭乳牛的起始位置:一個字元 N(朝北)或 E(朝東),以及兩個給出格子座標的非負整數 $x$ 和 $y$($0\le x\le 10^9$,$0\le y\le 10^9$)。所有 $x$ 座標互不相同,所有 $y$ 座標也互不相同。

為明確方向和座標,若乳牛在格子 $(x,y)$ 並向北移動,就到達 $(x,y+1)$。若改為向東移動,則到達 $(x+1, y)$。

輸出格式

輸出 $N$ 行。第 $i$ 行表示輸入中第 $i$ 頭乳牛吃掉了多少格的草。若一頭乳牛吃掉無限多的草,為牠輸出 Infinity。

範例

輸入格式 1

6
E 3 5
N 5 3
E 4 6
E 10 4
N 11 2
N 8 1

輸出格式 1

5
3
Infinity
Infinity
2
5

子任務

  • 測試點 $2$ 至 $5$ 的所有座標至多為 $100$。
  • 測試點 $6$ 至 $10$ 沒有額外限制。

題目作者:Brian Dean

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.