Codeforces 1169A Circle Metro
题目链接: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的更多相关文章
- Codeforces Round #562 (Div. 2) A.Circle Metro
链接:https://codeforces.com/contest/1169/problem/A 题意: The circle line of the Roflanpolis subway has n ...
- @codeforces - 1056G@ Take Metro
目录 @description@ @solution@ @accepted code@ @details@ @description@ 环上有 n 个点,按顺时针顺序以 1 到 n 编号.其中 1~m ...
- [Done] Codeforces Round #562 (Div. 2) 题解
A - Circle Metro 模拟几百步就可以了. B - Pairs 爆搜一下,时间复杂度大概是 $O(4 * n)$ Code: 56306723 C - Increasing by Modu ...
- [Educational Round 10][Codeforces 652F. Ants on a Circle]
题目连接:652F - Ants on a Circle 题目大意:\(n\)个蚂蚁在一个大小为\(m\)的圆上,每个蚂蚁有他的初始位置及初始面向,每个单位时间蚂蚁会朝着当前面向移动一个单位长度,在遇 ...
- Codeforces 652F Ants on a Circle
Ants on a Circle 感觉这个思路好巧妙啊. 我们能发现不管怎么碰撞,初始态和最终态蚂蚁间的相对顺序都是一样的, 并且所占的格子也是一样的, 那么我们就只需要 找到其中一个蚂蚁的最终位置就 ...
- Codeforces Round #555 (Div. 3) F. Maximum Balanced Circle
F. Maximum Balanced Circle 题目链接 题意 给出\(n\)个数,现在要从中选出最多的数\(b_i,b_{i+1},\cdots,b_k\),将这些数连成一个环,要求两两相邻的 ...
- Codeforces 1189B Number Circle
题目链接:http://codeforces.com/problemset/problem/1189/B AC代码: #include<bits/stdc++.h> using names ...
- 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 ...
- [模拟]Codeforces Circle of Students
Circle of Students time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- java并发编程笔记(五)——线程安全策略
java并发编程笔记(五)--线程安全策略 不可变得对象 不可变对象需要满足的条件 对象创建以后其状态就不能修改 对象所有的域都是final类型 对象是正确创建的(在对象创建期间,this引用没有逸出 ...
- java并发编程笔记(三)——线程安全性
java并发编程笔记(三)--线程安全性 线程安全性: 当多个线程访问某个类时,不管运行时环境采用何种调度方式或者这些进程将如何交替执行,并且在主调代码中不需要任何额外的同步或协同,这个类都能表现 ...
- The document cannot be opened. It has been renamed, deleted or moved.
In the Individual components section of the Visual Studio Installer, make sure that Razor Language S ...
- Git与GitHub同步
如何通过Git Bash实现本地与远端仓库——GitHub的同步 1.下载安装Git:下载网址 2.在自己的github上新建一个repository 例如我这里新建了一个叫test的reposito ...
- mysql 密码
http://www.cnblogs.com/jonsea/p/5510219.html character-set-server=utf8 mysql 修改密码: ALTER USER 'root' ...
- Shell判断某文件夹下是否存在xxx开头的字符串
Usage: bash judge_prefix_string.sh TARGET_DIR TARGET_STR #!/bin/bash TARGET_DIR=$1 TARGET_STR=$2 ls ...
- ZOJ 3795 Grouping(scc+最长路)
Grouping Time Limit: 2 Seconds Memory Limit: 65536 KB Suppose there are N people in ZJU, whose ...
- el-form-item内容过多,及弹窗框宽度属性show-overflow-tooltip设置
内容过多: :show-overflow-tooltip=true 宽度属性设置: .el-tooltip__popper{ max-width:30% }
- 树莓派上Opencv highgui的问题
错误描述:https://bbs.csdn.net/topics/394616975?page=1#post-409508178 解决方案:直接改系统环境变量 # vim /etc/profile e ...
- 快速上手的Glide4.x教程
安卓基础开发库,让开发简单点. DevRing & Demo地址:https://github.com/LJYcoder/DevRing 学习/参考地址: https://blog.csdn. ...