QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 1024 MB 満点: 100

#1956. 寻找房子

統計

Younghee 目前正处于一条一维道路上,寻找她朋友 Jisun 的家。为了获知 Jisun 家的确切位置,Younghee 给 Jisun 发送了一条包含她当前位置的消息(假设所有位置都用整数表示)。几分钟后,Younghee 收到了 Jisun 的回复,其中包含一个由 $n$ 个三元组组成的列表,并附带了以下说明:

  • 对于列表中的每个三元组 $(i, j, k)$,$i$ 是一个整数,表示当前位置;$j$ 表示从 $i$ 出发的方向,用 $L$(左)或 $R$(右)表示;$k$ 是一个正整数,表示从 $i$ 出发的移动距离。
  • 对于列表中的任意两个三元组 $(i, j, k)$ 和 $(i', j', k')$,$i$ 和 $i'$ 互不相同。
  • 如果你当前处于位置 $i$,列表中总会存在一个三元组 $(i, j, k)$(除非列表中的所有三元组都已被使用过)。在这种情况下,使用该三元组 $(i, j, k)$,并移动到 $i - k$(如果 $j = L$)或 $i + k$(如果 $j = R$)。
  • 列表中的每个三元组恰好被使用一次。
  • 使用完列表中所有的三元组之后的位置,即为 Jisun 家的位置。

例如,假设 Younghee 当前位于位置 $0$,列表包含四个三元组:$(3, R, 4)$、$(0, L, 2)$、$(7, L, 5)$ 和 $(-2, R, 5)$。那么 Younghee 首先使用三元组 $(0, L, 2)$ 并移动到位置 $0 - 2 = -2$。之后,Younghee 按顺序使用三元组 $(-2, R, 5)$、$(3, R, 4)$ 和 $(7, L, 5)$,最终移动到位置 $2$,这就是 Jisun 家的位置。给定 $n$、Younghee 的当前位置以及包含 $n$ 个三元组的列表,请编写一个程序来找出 Jisun 家的位置。

输入格式

程序从标准输入读取数据。输入的第一行包含一个整数 $n$ ($1 \le n \le 10,000$),表示列表中三元组的数量。接下来的 $n$ 行中,每行给出一个三元组,包含两个整数 $i$ 和 $k$ 以及一个字符 $j$ ($-1,000,000 \le i \le 1,000,000$,$j \in \{L, R\}$,$1 \le k \le 2,000,000$)。在 $n$ 行三元组之后,最后一行包含一个整数,表示 Younghee 的当前位置,取值范围在 $-1,000,000$ 到 $1,000,000$ 之间。

输出格式

程序将结果写入标准输出。请打印一行,包含 Jisun 家的位置。

样例

样例输入 1

4
3 R 4
0 L 2
7 L 5
-2 R 5
0

样例输出 1

2

样例输入 2

5
3 L 3
-1 R 11
5 L 6
1 R 4
10 L 7
1

样例输出 2

0

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.