Codeforces Round #394 (Div. 2) B. Dasha and friends
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length L, in distinct points of which there are n barriers. Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track.
Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the n barriers. Thus, each of them wrote n integers in the ascending order, each of them was between 0 and L - 1, inclusively.
Consider an example. Let L = 8, blue points are barriers, and green points are Kefa's start (A) and Sasha's start (B). Then Kefa writes down the sequence[2, 4, 6], and Sasha writes down [1, 5, 7].
There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they participated on different tracks.
Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction — counterclockwise, if you look on a track from above.
The first line contains two integers n and L (1 ≤ n ≤ 50, n ≤ L ≤ 100) — the number of barriers on a track and its length.
The second line contains n distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the range from 0 to L - 1 inclusively.
The second line contains n distinct integers in the ascending order — the distance from Sasha's start to each barrier in the order of its overcoming. All integers are in the range from 0 to L - 1 inclusively.
Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes).
3 8
2 4 6
1 5 7
YES
4 9
2 3 5 8
0 1 3 6
YES
2 4
1 3
1 2
NO
The first test is analyzed in the statement.
题意:给你一个环,然后让你安排A的起点和B的起点,使得某些特殊点到A的距离是a[i],某些点到B的距离是b[i],问你可不可行。
题解:暴力搜一遍
#include <iostream>
#include<cstdio>
using namespace std;
int n,l;
int a[],b[];
int main()
{
scanf("%d%d",&n,&l);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++) scanf("%d",&b[i]);
bool flag;
for(int i=;i<=n;i++)
{
int start=(a[i]-b[]+l)%l;
flag=;
for(int j=;j<=n;j++)//假设A的起点为0坐标
{
if (a[(i+j-)%n+]!=(start+b[j])%l) {flag=;break;}
}
if (flag) break;
}
if (flag) printf("YES\n"); else printf("NO\n");
return ;
}
Codeforces Round #394 (Div. 2) B. Dasha and friends的更多相关文章
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(分形)
E. Dasha and Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle 构造
E. Dasha and Puzzle 题目连接: http://codeforces.com/contest/761/problem/E Description Dasha decided to h ...
- Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心
D. Dasha and Very Difficult Problem 题目连接: http://codeforces.com/contest/761/problem/D Description Da ...
- Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力
C. Dasha and Password 题目连接: http://codeforces.com/contest/761/problem/C Description After overcoming ...
- Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力
B. Dasha and friends 题目连接: http://codeforces.com/contest/761/problem/B Description Running with barr ...
- Codeforces Round #394 (Div. 2) A. Dasha and Stairs 水题
A. Dasha and Stairs 题目连接: http://codeforces.com/contest/761/problem/A Description On her way to prog ...
- Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem —— 贪心
题目链接:http://codeforces.com/contest/761/problem/D D. Dasha and Very Difficult Problem time limit per ...
- Codeforces Round #394 (Div. 2) C. Dasha and Password —— 枚举
题目链接:http://codeforces.com/problemset/problem/761/C C. Dasha and Password time limit per test 2 seco ...
- Codeforces Round #394 (Div. 2) B. Dasha and friends —— 暴力 or 最小表示法
题目链接:http://codeforces.com/contest/761/problem/B B. Dasha and friends time limit per test 2 seconds ...
- Codeforces Round #394 (Div. 2) C. Dasha and Password
C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- ViewConfiguration 和 ViewConfigurationCompat
Contains methods to standard constants used in the UI for timeouts, sizes, and distances. 一.几个常用的方法 ...
- R-CNN for Small Object Detection
R-CNN for Small Object Detection 文章方法概括 这篇文章主要讨论针对小目标的目标检测 文章为了证明:对传统R-CNN style的方法进行改进,可以用于小目标检测,并且 ...
- js 实现无限加载分页(适合移动端)
一.原理:当滚动条到达底部时,执行下一页内容. 判断条件需要理解三个概念: 1.scrollHeight 真实内容的高度 2.clientHeight 视窗的高度,即在浏览器中所能看到的内 ...
- shell中的for、while、until(二)
1.C语言格式的for命令: for((var; condition;iteration process)) 注意: 1.给变量赋值可以有空格 2.条件中的变量不以美元符开头: 3.迭代过程的算式未用 ...
- 解锁CHM文件
刚在网上下载了CHM格式的文件,打开之后,右侧部分一片空白. 原因:可能是,系统针对来源不明文件的一种保存措施吧 解决方法: 1.选中文件,右键打开属性对话框,在 “常规”选项卡中 勾选 [解除锁定] ...
- jmeter常用插件安装
转载:http://www.cnblogs.com/danqiu/p/6119156.html 下载地址:http://jmeter-plugins.org/downloads/all/ PerfMo ...
- ng-click得到当前元素,
直接上代码: <!DOCTYPE html> <html> <head> <title></title> <script src=&q ...
- 20145201《Java程序设计》第九周学习总结
20145201 <Java程序设计>第九周学习总结 教材学习内容总结 JDBC是用于执行SQL的解决方案,开发人员使用JDBC的标准接口,数据库厂商则对接口进行操作,开发人员无须接触底层 ...
- 通过excel快速拼接SQL
“哎,发你一个excel,把这几百条数据修复喽.”经理喊道. “嗯,好的!” 正在看资料的我被经理临时分的任务打断,搞吧!这就是我平时中的一个工作场景. 工作中总是会遇到要修复数据,数据在excel中 ...
- Mybatis映射配置文件<select>的学习
resultMap的使用 当查询的表的列名与实体类的属性名不同时,有三种方式来处理: 1.使用SQL的别名 如:select user_name userName from user 2.如果符合驼峰 ...