CF1169A.Circle Metro
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The circle line of the Roflanpolis subway has n stations.
There are two parallel routes in the subway. The first one visits stations in order 1→2→…→n→1→2→… (so the next stop after station x is equal to (x+1) if x<n and 1 otherwise). The second route visits stations in order n→(n−1)→…→1→n→(n−1)→… (so the next stop after station x is equal to (x−1) if x>1 and n otherwise). All trains depart their stations simultaneously, and it takes exactly 1 minute to arrive at the next station.
Two toads live in this city, their names are Daniel and Vlad.
Daniel is currently in a train of the first route at station a and will exit the subway when his train reaches station x.
Coincidentally, Vlad is currently in a train of the second route at station b and he will exit the subway when his train reaches station y.
Surprisingly, all numbers a,x,b,y are distinct.
Toad Ilya asks you to check if Daniel and Vlad will ever be at the same station at the same time during their journey. In other words, check if there is a moment when their trains stop at the same station. Note that this includes the moments when Daniel or Vlad enter or leave the subway.
罗弗兰波利斯地铁的环线共有 n 个车站。
地铁中有两条平行运行的线路。第一条线路按顺序经过车站:1→2→…→n→1→2→…(即:若当前车站为 x,则下一站为 (x+1)(当 x<n 时)或 1(当 x=n 时))。第二条线路按顺序经过车站:n→(n−1)→…→1→n→(n−1)→…(即:若当前车站为 x,则下一站为 (x−1)(当 x>1 时)或 n(当 x=1 时))。所有列车同时从各自车站出发,且到达下一站恰好耗时 1 分钟。
这座城市住着两只蟾蜍,名叫丹尼尔(Daniel)和弗拉德(Vlad)。
丹尼尔此刻正乘坐第一条线路的列车,位于车站 a,当他所乘列车抵达车站 x 时,他将离开地铁。
巧合的是,弗拉德此刻正乘坐第二条线路的列车,位于车站 b,当他所乘列车抵达车站 y 时,他将离开地铁。
令人惊讶的是,四个数 a,x,b,y 互不相同。
蟾蜍伊利亚(Ilya)请你判断:在丹尼尔与弗拉德各自的旅程中,他们是否会在某一时刻同时出现在同一车站?换言之,请判断是否存在某个时刻,使得他们的列车同时停靠在同一车站。注意:该判断包含丹尼尔或弗拉德进入或离开地铁的时刻。
输入格式
The first line contains five space-separated integers n, a, x, b, y (4≤n≤100, 1≤a,x,b,y≤n, all numbers among a, x, b, y are distinct) — the number of stations in Roflanpolis, Daniel's start station, Daniel's finish station, Vlad's start station and Vlad's finish station, respectively.
第一行包含五个以空格分隔的整数 n、a、x、b、y(4≤n≤100,1≤a,x,b,y≤n,且 a、x、b、y 互不相同),分别表示罗弗兰波利斯市的车站数量、丹尼尔的起始车站、丹尼尔的终点车站、弗拉德的起始车站以及弗拉德的终点车站。
输出格式
Output "YES" if there is a time moment when Vlad and Daniel are at the same station, and "NO" otherwise. You can print each letter in any case (upper or lower).
如果存在某一时刻,弗拉德和丹尼尔位于同一车站,则输出“YES”;否则输出“NO”。每个字母可以以任意大小写形式输出(大写或小写)。
输入输出样例
输入#1
5 1 4 3 2
输出#1
YES
输入#2
10 2 1 9 10
输出#2
NO
说明/提示
In the first example, Daniel and Vlad start at the stations (1,3). One minute later they are at stations (2,2). They are at the same station at this moment. Note that Vlad leaves the subway right after that.
Consider the second example, let's look at the stations Vlad and Daniel are at. They are:
- initially (2,9),
- after 1 minute (3,8),
- after 2 minutes (4,7),
- after 3 minutes (5,6),
- after 4 minutes (6,5),
- after 5 minutes (7,4),
- after 6 minutes (8,3),
- after 7 minutes (9,2),
- after 8 minutes (10,1),
- after 9 minutes (1,10).
After that, they both leave the subway because they are at their finish stations, so there is no moment when they both are at the same station.
在第一个例子中,丹尼尔和弗拉德从车站 (1,3) 出发。一分钟后,他们到达车站 (2,2)。此时他们位于同一车站。注意,弗拉德在此之后立即离开地铁。
考虑第二个例子,我们来看弗拉德和丹尼尔所处的车站。他们的位置依次为:
- 初始时刻:(2,9),
- 1 分钟后:(3,8),
- 2 分钟后:(4,7),
- 3 分钟后:(5,6),
- 4 分钟后:(6,5),
- 5 分钟后:(7,4),
- 6 分钟后:(8,3),
- 7 分钟后:(9,2),
- 8 分钟后:(10,1),
- 9 分钟后:(1,10)。
此后,他们均因抵达各自的终点站而离开地铁,因此不存在两人同时位于同一车站的时刻。
输入解题思路,AI测评打分。不知道怎么写?