滴答滴答---题目小连接

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Output

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

Examples

input

Copy

5 1 4 3 2

output

Copy

YES

input

Copy

10 2 1 9 10

output

Copy

NO

Note

In the first example, Daniel and Vlad start at the stations (1,3)(1,3). One minute later they are at stations (2,2)(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)(2,9),
  • after 11 minute (3,8)(3,8),
  • after 22 minutes (4,7)(4,7),
  • after 33 minutes (5,6)(5,6),
  • after 44 minutes (6,5)(6,5),
  • after 55 minutes (7,4)(7,4),
  • after 66 minutes (8,3)(8,3),
  • after 77 minutes (9,2)(9,2),
  • after 88 minutes (10,1)(10,1),
  • after 99 minutes (1,10)(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.

#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int maxn=1010;
int l[maxn];
int r[maxn];
int main()
{int n,a,b,x,y;scanf("%d%d%d%d%d",&n,&a,&x,&b,&y);int flas=0;int l1,r1;l1=r1=0;for(int i=a; i<=n; i++){l[l1++]=i;}for(int i=1; i<a; i++){l[l1++]=i;}for(int i=b; i>=1; i--){r[r1++]=i;}for(int i=n; i>b; i--){r[r1++]=i;}for(int i=1; i<=n; i++){if(l[i]==r[i]){flas=1;break;}else if(l[i]==x||r[i]==y)break;}cout<<(flas==1?"YES":"NO")<<endl;return 0;
}

方法二:

#include<bits/stdc++.h>
using namespace std;
int main(){int n,a,b,c,d;cin>>n>>a>>b>>c>>d;while(a!=b&&c!=d){if(a==n)a=1;else a++;if(c==1)c=n;else c--;if(a==c)return puts("YES"),0;}puts("NO");
}

A. Circle Metro相关推荐

  1. Circle Metro CodeForces - 1169A

    Circle Metro The circle line of the Roflanpolis subway has nn stations. There are two parallel route ...

  2. Codeforces Round #562 (Div. 2) A.Circle Metro

    链接:https://codeforces.com/contest/1169/problem/A 题意: The circle line of the Roflanpolis subway has n ...

  3. codeforces竞赛1169题解

    A. Circle Metro 题目大意: 两个人乘坐不同方向的环形地铁,求两人是否会在某一站点相遇. 解题思路: 模拟即可 AC代码: 版本一(下标模拟) #include<bits/stdc ...

  4. php 顺时针打印矩阵,这题

    浅谈狄利克雷相关题目套路2021-03-25 21:58:20 啥都不知道,被yyc D爆了/kk 扔道题 P2714 四元组统计 乍一看,就想推式子,结果发现自己是个憨批 莫反就两条式子 考虑第二种 ...

  5. OpenCV 学习笔记03 boundingRect、minAreaRect、minEnclosingCircle、boxPoints、int0、circle、rectangle函数的用法...

    函数中的代码是部分代码,详细代码在最后 1 cv2.boundingRect 作用:矩形边框(boundingRect),用于计算图像一系列点的外部矩形边界. cv2.boundingRect(arr ...

  6. 关闭Windows 8的metro UI的方法汇总

    http://www.ssdax.com/570.html 上面就是windows8新出现的Metro UI,点击开始菜单就会出现,取代了windows长久以来的开始菜单,有了非常大的突破 不过我发现 ...

  7. MahApps.Metro

    ModernUI for WPF Mahapps.metro home Mahapps.metro Quick start Mahapps.metro controls 转载于:https://www ...

  8. 旷视提Circle Loss,统一优化视角,革新深度特征学习范式 | CVPR 2020

    作者 | 旷视研究院 本文是旷视 CVPR 2020的被收录论文解读第.它提出用于深度特征学习的Circle Loss,从相似性对优化角度正式统一了两种基本学习范式(分类学习和样本对学习)下的损失函数 ...

  9. CVPR 2020 Oral | 旷视提出Circle Loss,革新深度特征学习范式

    点击上方"视学算法",选择加"星标"或"置顶" 重磅干货,第一时间送达 本文系旷视研究院投稿 本文是旷视CVPR2020论文系列解读第4篇, ...

最新文章

  1. 千万级智能推荐系统架构演进!
  2. 移动端video隐藏进度条_机器学习模型部署--打通前后端任督二脉
  3. 20145227鄢曼君《网络对抗》逆向及Bof基础
  4. 【转】iOS类似Android上toast效果
  5. Linux环境升级node版本
  6. linux查看网卡硬件 lsw,无人值守网络安装Linux系统
  7. html中图片阴影怎么写,css如何给图片加阴影?
  8. 自动驾驶 8-4: 最小二乘法和最大似然法 Least Squares and the Method of Maximum Likelihood
  9. php读取excel 报错_php读取excel文件
  10. 集成建行龙支付(2019.01.24更新)
  11. 计算机科普扫盲——固态硬盘
  12. 拼图(九宫格,十六宫格)
  13. 快圣诞节了,用Python 送你一棵圣诞树
  14. 【c++篇】c++常见容器中list的模拟实现
  15. 论文:并行化 Metropolis-Hastings 算法的一般结构
  16. 寻路问题——找到从起点到终点路径
  17. 如何高效回复审稿意见?(附常用审稿意见回复模板)
  18. 全球及中国富维生素矿物质食品行业研究及十四五规划分析报告
  19. jquery 删除数组
  20. python 下载图片

热门文章

  1. 中国古生物学家获得2018年欧莱雅基金会-联合国教科文组织女性科学家奖
  2. WPF开发经验-WPF的TextBox控件的MouseDown事件不响应的解决方法
  3. String s=“abc“ 和 String s1=new String(“abc“)和String s2=new String(“abc“)之间的关系
  4. android:SeekBar控制系统音量(媒体音量键和通话音量键的diallog自动切换调节控制)
  5. java的异常类_各种Java异常类大集合,精辟精辟精辟
  6. 基于javaEE的图书管理系统
  7. Windows 系统错误代码大全3
  8. 常用 JS 【验证函数】
  9. 【webgl】模拟摄像机
  10. 【CF】1772E-Permutation Game 题解