# Circle Metro CodeForces - 1169A

The circle line of the Roflanpolis subway has nn stations.
There are two parallel routes in the subway. The first one visits stations in order 1→2→…→n→1→2→…1→2→…→n→1→2→… (so the next stop after station xx is equal to (x+1)(x+1) if x<nx<n and 11 otherwise). The second route visits stations in order n→(n−1)→…→1→n→(n−1)→…n→(n−1)→…→1→n→(n−1)→… (so the next stop after station xx is equal to (x−1)(x−1) if x>1x>1 and nn otherwise). All trains depart their stations simultaneously, and it takes exactly 11 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 aa and will exit the subway when his train reaches station xx.
Coincidentally, Vlad is currently in a train of the second route at station bb and he will exit the subway when his train reaches station yy.
Surprisingly, all numbers a,x,b,ya,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.

input
The first line contains five space-separated integers nn, aa, xx, bb, yy (4≤n≤1004≤n≤100, 1≤a,x,b,y≤n1≤a,x,b,y≤n, all numbers among aa, xx, bb, yy 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

ouput
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)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int a,x,b,y,n;
scanf("%d%d%d%d%d",&n,&a,&x,&b,&y);
int flag=0;
while(a!=x&&b!=y)
{
if(a==n)
{
a=1;
}
else
{
a++;
}
if(b==1)
{
b=n;
}
else
{
b--;
}
if(a==b)
{
flag=1;
break;
}
}
if(flag==1)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
return 0;
}

• 点赞
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 打赏

打赏

没事刷一道

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 举报
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文

05-29 173
05-28 504
05-28 182
05-30 83
05-27 299
07-28
01-21 3626
03-06
05-12