博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【codeforces 761B】Dasha and friends
阅读量:5149 次
发布时间:2019-06-13

本文共 3667 字,大约阅读时间需要 12 分钟。

time limit per test2 seconds

memory limit per test256 megabytes
inputstandard input
outputstandard 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.

【题目链接】:

【题解】

给你两个环,问你能不能改变开始位置,逆时针转,使得两人遇到障碍物离初始点的距离构成的序列相同;
第一个人不动,改变第二个人的开始位置;看看在路上遇到的障碍物构成的序列和不和第一个相同;不同则继续枚举;
复杂度O(L^2)
【完整代码】

#include 
using namespace std;const int MAXN = 50+10;const int MAXL = 100+10;int n,l;int a[MAXN],b[MAXN],c[MAXN];bool bo[MAXL];void youjie(){ puts("YES"); exit(0);}bool ok(){ for (int i = 1;i <= n;i++) if (a[i]!=c[i]) return false; return true;}int main(){ //freopen("F:\\rush.txt","r",stdin); cin >> n >> l; for (int i = 1;i <= n;i++) cin >> a[i]; for (int i = 1;i <= n;i++) { cin >> b[i]; c[i] = b[i]; bo[b[i]] = true; } if (ok()) youjie(); for (int i = 1;i <= l-1;i++) { int num = 0,cnt = 0; int j = i; while (num < n) { if (bo[j]) c[++num] = cnt; cnt++; j++; if (j==l) j = 0; } if (ok()) youjie(); } puts("NO"); return 0;}

转载于:https://www.cnblogs.com/AWCXV/p/7626659.html

你可能感兴趣的文章
2019-08-29开始——光网络
查看>>
解决sublime安装插件被墙失败的方法
查看>>
CentOS 安装jira 6.3.6
查看>>
按钮UIButton的使用
查看>>
C++利用SOAP开发WebService
查看>>
ToDo
查看>>
Hadoop入门经典:WordCount
查看>>
BZOJ-1029 建筑抢修
查看>>
tornado基础入门(一)——简单了解tornado
查看>>
WebSocket 协议
查看>>
【BZOJ 4103】 [Thu Summer Camp 2015]异或运算 可持久化01Trie
查看>>
数据类型
查看>>
CodeForces - 566F Clique in the Divisibility Graph
查看>>
CodeForces - 986C AND Graph
查看>>
[JZOJ5455]【NOIP2017提高A组冲刺11.6】拆网线
查看>>
【MySql】Order By 排序
查看>>
jQuery选择器
查看>>
spring字符编码filter
查看>>
thinkphp5省市区三级联动例子
查看>>
让HttpClient不要打印巨多的日志
查看>>