B. Dasha and friends
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

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.

Input

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.

Output

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

Examples
input
3 8
2 4 6
1 5 7
output
YES
input
4 9
2 3 5 8
0 1 3 6
output
YES
input
2 4
1 3
1 2
output
NO
Note

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的更多相关文章

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

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

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

  4. Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力

    C. Dasha and Password 题目连接: http://codeforces.com/contest/761/problem/C Description After overcoming ...

  5. Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力

    B. Dasha and friends 题目连接: http://codeforces.com/contest/761/problem/B Description Running with barr ...

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

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

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

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

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

随机推荐

  1. Django - 权限(2)- 动态显示单级权限菜单

    一.权限组件 1.上篇随笔中,我们只是设计好了权限控制的表结构,有三个模型,五张表,两个多对多关系,并且简单实现了对用户的权限控制,我们会发现那样写有一个问题,就是权限控制写死在了项目中,并且没有实现 ...

  2. Web Service简单demo

    最近开发因需求要求需要提供Web Service接口供外部调用,由于之前没有研究过该技术,故查阅资料研究了一番,所以写下来记录一下,方便后续使用. 这个demo采用CXF框架进行开发,后续所提到的We ...

  3. C#多线程同步案例实操

    好久没有写博客了,为了养成学习的习惯,培养积极年轻的心态,又回到了博客园这个平台继续撸起时隔多年未光顾的空间. 项目需求: 实现一个简单的获取始发目的耗时.距离,将结果输出表格. 方案思路: 通过多线 ...

  4. this的思考

    问题:JS中为什么要用this? 回答:因为this采用隐式“传递”一个对象的引用,所以可以将API设计得更加简洁和可复用 问题:JS中的this是什么? 背景:this是在运行时绑定的,this的上 ...

  5. python 系统相关操作

    1.文件 open()代开文件或者创建文件 fout=open('oops.txt','wt') print('Oops, I created a file.',file=fout) fout.clo ...

  6. MySQL引擎及选择

    一.MySQL的存储引擎 完整的引擎说明还是看官方文档:http://dev.mysql.com/doc/refman/5.6/en/storage-engines.html 这里介绍一些主要的引擎 ...

  7. JavaWeb JavaScript

    1.JavaScript概述 JavaScript是一种基于对象和事件驱动的脚本语言,原名叫做livescript.W3c组织开发的标准叫ECMAscipt 1.1JavaScript和Java的一些 ...

  8. redis_入门网址

    redis中文网: http://www.redis.cn/ 可以 试用 以及 下载 redis百度百科:http://baike.baidu.com/link?url=MEkE5MpGAOfJ7ci ...

  9. 开源CMDB详细安装使用

    CMDB的GitHub地址: https://github.com/open-cmdb/cmdb 环境说明 [root@WCY ~]# cat /etc/redhat-release CentOS L ...

  10. 利用web workers实现多线程处理

    利用web workers在后台线程中实现对数据库的增删改查操作,并在后台线程中生成页面上某个列表的完整的HTML代码,然后再前台脚本中直接将这段HTML代码输出到页面上! 利用web workers ...