题目链接:codeforces.com/contest/1169/problem/A


题意:有俩个地铁,一个从 1 → 2 → …→ n → 1→ 2 →…, 一个 从 n → n-1 →…→ 1 → n → n-1→ …。地铁同时开并且地铁经过一个站的时间都相同,俩个人一个坐前面那俩,一个坐后面那俩,给你他们的起点站和终点站,问他们在这过程中有没有可能同时在一个站,可能就输出YES,否则输出NO。

思路:一个 i 从 起始 a 开始加 ,一个 j 从 b 开始减,如果 i 加到 n+1 就让它返回 1,j 减到 0令他返回n,如果 i == j 说明在同一个站。如果 i 或者 j 有一方到达终点站 x 或 y,则结束。

AC代码:

 #include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n,a,b,x,y;
while(cin >> n >> a >> x >> b >> y)
{
bool flag = false;
for(int i = a,j = b;;i++,j--)
{
if(i == n + ) i = ;
if(j == ) j = n;
if(i == j)
{
flag = true;break;
}
if(i == x || j == y) break;
}
if(flag) cout << "YES" << endl;
else cout << "NO" << endl;
}
return ;
}

Codeforces 1169A Circle Metro的更多相关文章

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

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

  2. @codeforces - 1056G@ Take Metro

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 环上有 n 个点,按顺时针顺序以 1 到 n 编号.其中 1~m ...

  3. [Done] Codeforces Round #562 (Div. 2) 题解

    A - Circle Metro 模拟几百步就可以了. B - Pairs 爆搜一下,时间复杂度大概是 $O(4 * n)$ Code: 56306723 C - Increasing by Modu ...

  4. [Educational Round 10][Codeforces 652F. Ants on a Circle]

    题目连接:652F - Ants on a Circle 题目大意:\(n\)个蚂蚁在一个大小为\(m\)的圆上,每个蚂蚁有他的初始位置及初始面向,每个单位时间蚂蚁会朝着当前面向移动一个单位长度,在遇 ...

  5. Codeforces 652F Ants on a Circle

    Ants on a Circle 感觉这个思路好巧妙啊. 我们能发现不管怎么碰撞,初始态和最终态蚂蚁间的相对顺序都是一样的, 并且所占的格子也是一样的, 那么我们就只需要 找到其中一个蚂蚁的最终位置就 ...

  6. Codeforces Round #555 (Div. 3) F. Maximum Balanced Circle

    F. Maximum Balanced Circle 题目链接 题意 给出\(n\)个数,现在要从中选出最多的数\(b_i,b_{i+1},\cdots,b_k\),将这些数连成一个环,要求两两相邻的 ...

  7. Codeforces 1189B Number Circle

    题目链接:http://codeforces.com/problemset/problem/1189/B AC代码: #include<bits/stdc++.h> using names ...

  8. Codeforces Round #564 (Div. 2) D. Nauuo and Circle(树形DP)

    D. Nauuo and Circle •参考资料 [1]:https://www.cnblogs.com/wyxdrqc/p/10990378.html •题意 给出你一个包含 n 个点的树,这 n ...

  9. [模拟]Codeforces Circle of Students

    Circle of Students time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. Java关于Math类的三个取整方法

    0x01 在java的Math类中有三个关于浮点数取整数的方法,分别是ceil (向上取整) floor(向下取整) round(四舍五入) 三个方法 0x02 ceil 向上取整,取整后总是比原来的 ...

  2. .net Core 在 CentOS7下,报The type initializer for 'Gdip' threw an exception.异常

    .net Core允许在 Centos7 上,使用 System.Draw.Common类库时,报以下错误: "Class":"System.TypeInitializa ...

  3. MySQL数据库学习初步

    我使用的环境是Win7,开始学习PHP和MySQL,并且买了本<Head First PHP & MySQL>,可以从Head First Labs官网获得HeadFirst系列书 ...

  4. Python之lambda && reduce

    lambda类似于C里面的#define或者C++里面的内联函数(inline),一般都小巧精悍 >>> g=lambda x,y:x*y >>> g(3,7) 2 ...

  5. .net EntityFramework dbContext 如何实例化

    1 .DbContext怎么在Asp.mvc中使如何实例化 public class Repository { //实例化EF容器:有弊端.一个线程里可能会创建多个DbContext //DbCont ...

  6. linux常用命令-1系统相关命令

    hostname #计算机名 passwd #修改密码 reboot #重启 shutdown –r now #立刻重启(root用户使用) shutdown –r 10 #过10分钟自动重启(roo ...

  7. linux网络配置 转

    1.常用配置网络指令 (1) 配置eth0的IP地址, 同时激活该设备 1 sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up (2) 添 ...

  8. 微信小程序 滚动到底部

    1.html <view id="bottom"></view> 2. onReady: function () { //滚动到底部 let query = ...

  9. SQL关于:警告: 聚合或其他 SET 操作消除了空值。

    方法一: create table tb ( id int, num int ) insert into tb select 1,10 insert into tb select 1,20 inser ...

  10. HTML5 worker计数器简单示例

    效果图: index.html var w; // 开始 function startWorker() { if (typeof (Worker) !== "undefined") ...