CF1056G.Take Metro
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Having problems with tram routes in the morning, Arkady decided to return home by metro. Fortunately for Arkady, there is only one metro line in the city.
Unfortunately for Arkady, the line is circular. It means that the stations are enumerated from 1 to n and there is a tunnel between any pair of consecutive stations as well as between the station 1 and the station n. Trains that go in clockwise direction visit the stations in order 1→2→3→…→n→1 while the trains that go in the counter-clockwise direction visit the stations in the reverse order.
The stations that have numbers from 1 to m have interior mostly in red colors while the stations that have numbers from m+1 to n have blue interior. Arkady entered the metro at station s and decided to use the following algorithm to choose his way home.
- Initially he has a positive integer t in his mind.
- If the current station has red interior, he takes a clockwise-directed train, otherwise he takes a counter-clockwise-directed train.
- He rides exactly t stations on the train and leaves the train.
- He decreases t by one. If t is still positive, he returns to step 2. Otherwise he exits the metro.
You have already realized that this algorithm most probably won't bring Arkady home. Find the station he will exit the metro at so that you can continue helping him.
早上乘坐有轨电车出行遇到问题后,阿尔卡季决定改乘地铁回家。幸运的是,这座城市只有一条地铁线路。
不幸的是,这条线路是环形的。这意味着车站编号为 1 到 n,任意两个相邻车站之间均有一条隧道,此外车站 1 与车站 n 之间也有一条隧道。顺时针方向行驶的列车依次经过车站:1→2→3→…→n→1;而逆时针方向行驶的列车则按相反顺序经过车站。
编号为 1 到 m 的车站内部主色调为红色,编号为 m+1 到 n 的车站内部主色调为蓝色。阿尔卡季在车站 s 进入地铁,并决定采用以下算法选择回家路径:
- 最初他心中记着一个正整数 t;
- 若当前所在车站为红色内饰,则乘坐顺时针方向列车;否则乘坐逆时针方向列车;
- 他在该列车上恰好乘坐 t 站后下车;
- 将 t 减 1;若 t 仍为正数,则返回步骤 2;否则离开地铁。
你已经意识到,该算法极大概率无法将阿尔卡季送回家。请找出他最终离开地铁时所在的车站,以便你继续帮助他。
输入格式
The first line contains two integers n and m (3≤n≤105, 1≤m<n) — the total number of stations and the number of stations that have red interior.
The second line contains two integers s and t (1≤s≤n, 1≤t≤1012) — the starting station and the initial value of t.
第一行包含两个整数 n 和 m(3≤n≤105,1≤m<n)—— 分别表示车站总数和内部为红色的车站数量。
第二行包含两个整数 s 和 t(1≤s≤n,1≤t≤1012)—— 分别表示起始车站和 t 的初始值。
输出格式
Output the only integer — the station where Arkady will exit the metro.
输出唯一的整数——阿尔卡季将要出地铁的车站编号。
输入输出样例
输入#1
10 4 3 1
输出#1
4
输入#2
10 4 3 5
输出#2
4
输入#3
10543 437 5492 1947349
输出#3
438
说明/提示
Consider the first example. There are 10 stations and the first 4 of them are red. Arkady starts at station 3 with value t=1, so just rides 1 station in clockwise direction and ends up on the station 4.
In the second example the metro is same as in the first example, but Arkady starts at station 3 with value t=5.
- It is a red station so he rides 5 stations in clockwise direction and leaves the train at station 8.
- It is a blue station, so he rides 4 stations in counter-clockwise direction and leaves at station 4.
- It is a red station, so he rides 3 stations in clockwise direction and leaves at station 7.
- It is a blue station, so he rides 2 stations in counter-clockwise direction and leaves at station 5.
- It is a blue station, so he rides 1 station in counter-clockwise direction and leaves at station 4.
Now t=0, so Arkady exits metro at the station 4.
考虑第一个例子。共有 10 个车站,其中前 4 个为红色车站。Arkady 从第 3 号车站出发,初始值 t=1,因此他顺时针骑行 1 站,最终到达第 4 号车站。
在第二个例子中,地铁结构与第一个例子相同,但 Arkady 从第 3 号车站出发,初始值 t=5。
- 当前车站为红色,因此他顺时针骑行 5 站,并在第 8 号车站下车。
- 当前车站为蓝色,因此他逆时针骑行 4 站,并在第 4 号车站下车。
- 当前车站为红色,因此他顺时针骑行 3 站,并在第 7 号车站下车。
- 当前车站为蓝色,因此他逆时针骑行 2 站,并在第 5 号车站下车。
- 当前车站为蓝色,因此他逆时针骑行 1 站,并在第 4 号车站下车。
此时 t=0,因此 Arkady 在第 4 号车站离开地铁。
输入解题思路,AI测评打分。不知道怎么写?