Codeforces761B Dasha and friends 2017-02-05 23:34 162人阅读 评论(0) 收藏
2 seconds
256 megabytes
standard input
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.
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.
——————————————————————————————————————————————————————————————————
题目的意思是有两个人站在一个环上不同的位置记录前方的点到自己的距离,有没有可能存在一个换符合条件
不管人怎么站,每个点之间差值一定一样,随意算出差值然后枚举遍历是否相同。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
#define MAXN 100005 int a[1000],b[1000];
int x[1000],y[1000];
int l,n;
int main()
{
while(~scanf("%d%d",&n,&l))
{
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=0;i<n-1;i++)
x[i]=a[i+1]-a[i];
x[n-1]=a[0]+l-a[n-1]; for(int i=0;i<n;i++)
scanf("%d",&b[i]);
for(int i=0;i<n-1;i++)
y[i]=b[i+1]-b[i];
y[n-1]=b[0]+l-b[n-1];
int fl=0;
for(int i=0;i<n;i++)
{
int flag=0;
for(int j=0;j<n;j++)
{
int xx=j;
int yy=j+i;
if(yy>=n)
yy-=n;
if(x[xx]!=y[yy])
{
flag=1;
break;
}
}
if(flag==0)
{
fl=1;
break;
}
}
if(fl==1)
printf("YES\n");
else
printf("NO\n"); }
return 0;
}
Codeforces761B Dasha and friends 2017-02-05 23:34 162人阅读 评论(0) 收藏的更多相关文章
- POJ1679 The Unique MST 2017-04-15 23:34 29人阅读 评论(0) 收藏
The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29902 Accepted: 10697 ...
- Codeforces761A Dasha and Stairs 2017-02-05 23:28 114人阅读 评论(0) 收藏
A. Dasha and Stairs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- NYOJ-235 zb的生日 AC 分类: NYOJ 2013-12-30 23:10 183人阅读 评论(0) 收藏
DFS算法: #include<stdio.h> #include<math.h> void find(int k,int w); int num[23]={0}; int m ...
- ZOJ2482 IP Address 2017-04-18 23:11 44人阅读 评论(0) 收藏
IP Address Time Limit: 2 Seconds Memory Limit: 65536 KB Suppose you are reading byte streams fr ...
- ZOJ3704 I am Nexus Master! 2017-04-06 23:36 56人阅读 评论(0) 收藏
I am Nexus Master! Time Limit: 2 Seconds Memory Limit: 65536 KB NexusHD.org is a popular PT (Pr ...
- 使用URLConnection获取网页信息的基本流程 分类: H1_ANDROID 2013-10-12 23:51 3646人阅读 评论(0) 收藏
参考自core java v2, chapter3 Networking. 注:URLConnection的子类HttpURLConnection被广泛用于Android网络客户端编程,它与apach ...
- 认识C++中的临时对象temporary object 分类: C/C++ 2015-05-11 23:20 137人阅读 评论(0) 收藏
C++中临时对象又称无名对象.临时对象主要出现在如下场景. 1.建立一个没有命名的非堆(non-heap)对象,也就是无名对象时,会产生临时对象. Integer inte= Integer(5); ...
- Uniform Generator 分类: HDU 2015-06-19 23:26 11人阅读 评论(0) 收藏
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hilbert矩阵 分类: 数学 2015-07-31 23:03 2人阅读 评论(0) 收藏
希尔伯特矩阵 希尔伯特矩阵是一种数学变换矩阵 Hilbert matrix,矩阵的一种,其元素A(i,j)=1/(i+j-1),i,j分别为其行标和列标. 即: [1,1/2,1/3,--,1/n] ...
随机推荐
- 玩转Panabit 2008 Live CD到U盘,Panabit随身行
直接将Panabit 2008 Live CD的内容复制到U盘,即把Live CD转成U盘启动盘,U盘可写,方便保存配置.要能正常使用,必须机器支持USB启动,才能用上:但是熟悉此方法,同样可以灵活用 ...
- 浅析 MySQL Replication(转)
目前很多公司中的生产环境中都使用了MySQL Replication ,也叫 MySQL 复制,搭建配置方便等很多特性让 MySQL Replication 的应用很广泛,我们曾经使用过一主拖20多个 ...
- 使用 Lombok 简化项目中无谓的Java代码
在写使用Java时,难免会有一些模板代码要写,不然get/set,toString, hashCode, close 资源,定义构造函数等等.代码会显得很冗余,很长.Lombok项目可以是我们摆脱这些 ...
- win2008以上的系统,在vmware esxi5.5里怎么使用自定义规范管理器?sysprep
经过测试,原来08以上的系统自带了sysprep.exe,所以vcenter对08以上的系统直接使用自定义规范管理器即可,跟linux一样了.注意不要跟03一样写入了sn即可. vCenter可使用s ...
- Oracle 11g 新特性 -- Oracle Restart 说明(转载)
转载:http://blog.csdn.net/tianlesoftware/article/details/8435670 一. OHASD 说明 Oracle 的Restart 特性是Oracl ...
- Mysql 备份脚本和window下如何实现自动备份
@echo offecho.echo MySQL数据库备份 echo *****************************echo.echo 今天是 %date%echo 时间是 %t ...
- Mongodb 集群加keyFile认证
介绍 自从远古计绳结开始,数据库的存储就注定了今天的地位和多样性,Nosql的出现更是解决了现有的关系型数据库无法解决的一些难题,对高性能,灵活度,扩展性,海量数据的问题.随之而出现的高速内存索引数据 ...
- Numpy的ndarry:一种多维数组对象
Numpy的ndarry:一种多维数组对象 Numpy最重要的一个特点就是其N维数组对象(即ndarry),该对象是一个快速而灵活的大数据集容器.你可以利用这种数组对整块数据执行一些数学运算,其语法跟 ...
- Spring MVC 学习 之 - URL参数传递
在学习 Spring Mvc 过程中,有必要来先了解几个关键参数: @Controller: 在类上注解,则此类将编程一个控制器,在项目启动 Spring 将自动扫描此类,并进行对应URL路由映 ...
- web api的新玩法
前言: 目前大多数的.net core 项目的web api 都是用的json作为数据传输格式,或者说几乎是所有的都是,可是有没有想过换一种数据传输格式怎么处理,比如XML,或者谷歌首推的Protob ...