Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力
B. Dasha and friends
题目连接:
http://codeforces.com/contest/761/problem/B
Description
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).
Sample Input
3 8
2 4 6
1 5 7
Sample Output
YES
Hint
题意
给你一个环,然后让你安排A的起点和B的起点,使得某些特殊点到A的距离是a[i],某些点到B的距离是b[i],问你可不可行。
题解:
先把A的起点随便定在一个位置,然后暴力枚举B的起点就好了。
数据范围大一点好玩一点,这个数据范围太小了,所以自己暴力就行了。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int p[maxn],n,l,a[maxn],b[maxn],c[maxn];
int main()
{
scanf("%d%d",&n,&l);
for(int i=0;i<n;i++)
scanf("%d",&a[i]),p[a[i]]=1;
for(int j=0;j<n;j++)
scanf("%d",&b[j]);
for(int i=0;i<l;i++){
memset(c,0,sizeof(c));
int now=i;
for(int j=0;j<n;j++)
c[(now+b[j])%l]=1;
int flag = 0;
for(int j=0;j<l;j++)
{
if(c[j]!=p[j])
{
flag = 1;
break;
}
}
if(flag==0){
cout<<"YES"<<endl;
return 0;
}
}
cout<<"NO"<<endl;
}
Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力的更多相关文章
- 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 —— 暴力 or 最小表示法
题目链接:http://codeforces.com/contest/761/problem/B B. Dasha and friends time limit per test 2 seconds ...
- 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) 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) C. Dasha and Password
C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- Shell中的case命令
case语句和判断语句[if...elif...else]功能类似;当在逻辑判断比较简单的情况下,比后者的代码量要少许多.case用法,用变量来匹配某值,如果匹配成功则执行它下面的命令,直到 ::为止 ...
- Git error: hint: Updates were rejected because the remote contains work that you do hint: not have locally
hint: Updates were rejected because the remote contains work that you dohint: not have locally. This ...
- Automate Tdxw
Automate trade module in Tdxw Code # coding: utf-8 """ Created on Thu Dec 07 10:57:45 ...
- html5 canvas高级贝塞尔曲线运动动画(好吧这一篇被批的体无完肤!都说看不懂了!没办法加注释了!当然数学不好的我也没办法了,当然这还涉及到一门叫做计算机图形学的学科)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 20155305乔磊2016-2017-2《Java程序设计》第六周学习总结
20155305乔磊2016-2017-2<Java程序设计>第六周学习总结 教材学习内容总结 InputStream与OutputStream 串流设计 1.串流:Java将输入/输出抽 ...
- [BZOJ 2299][HAOI 2011]向量 题解(裴蜀定理)
[BZOJ 2299][HAOI 2011]向量 Description 给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), ...
- ACM数据对拍程序
#include<cstdio> #include<cstdlib> #include<ctime> int main() { long s,t; while(1) ...
- Web安全测试-WebScarab
[功能] WebScarab是一个用来分析使用HTTP和HTTPS协议的应用程序框架.其原理很简单,WebScarab可以记录它检测到的会话内容(请求和应答),并允许使用者可以通过多种形式来查看记录. ...
- 深入理解C语言的函数调用过程 【转】
转自:http://blog.chinaunix.net/uid-25909619-id-4240084.html 原文地址:深入理解C语言的函数调用过程 作者:wjlkoorey258 本文 ...
- mitmdump 屏蔽443错误
mitmdump --ignore-hosts ".*443$" -s test.py