题目链接:http://codeforces.com/contest/761/problem/B

题意:给定一个环形跑道。里面有n个障碍,跑道长度为L。然后有两个人在两个起点(起点可能相同),每个人都按逆时针走。现在给出这两个人遇到这n个障碍时走的步数。问是否存在合法的障碍分布。
思路:我们假设第一个人的起点为原点。那么对于第一个人来说n个障碍的位置就是对于他的输入序列。然后枚举第二个人的起点。根据第二个人的序列来判断是否和第一个人的位置一样。一样则说明存在合法分布。 注意由于跑道是环形所以要进行取模。

import java.io.PrintWriter;
import java.util.*; public class Main {
public static final int MAXN=100+5;
public static int v[]=new int [MAXN];
public static int pa[]=new int [MAXN];
public static int pb[]=new int [MAXN];
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n=cin.nextInt(),L=cin.nextInt();
boolean flag=false;
Arrays.fill(v, 0);
for(int i=0;i<n;i++){
pa[i]=cin.nextInt();
v[pa[i]]=1;
}
for(int i=0;i<n;i++){
pb[i]=cin.nextInt();
}
for(int i=0;i<L;i++){
Set<Integer>se=new HashSet<Integer>();
for(int j=0;j<n;j++){
if(v[(i+pb[j])%L]==1){
se.add((i+pb[j])%L);
}else{
break;
}
}
if(se.size()==n){
flag=true; break;
}
}
out.printf(flag?"YES":"NO");
cin.close();
out.flush();
}
}

Codeforces Round #394 (Div. 2) - B的更多相关文章

  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) 颓废记

    昨天晚上(今天凌晨),又忍不住去打CF.(本蒟弱到只能打Div.2)... 我觉得我可以用一个词概括我这次的CF: 呵呵 刚一开赛,我就codeforces访问失败.. 后来好不容易能上了,两三分钟才 ...

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

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

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

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

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

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

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

  8. Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(dfs)

    http://codeforces.com/contest/761/problem/E 题意:给出一棵树,现在要把这棵树上的结点放置在笛卡尔坐标上,使得每一条边与x轴平行或者与y轴平行.输出可行解,即 ...

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

    http://codeforces.com/contest/761/problem/C 题意:给出n个串,每个串的初始光标都位于0(列)处,怎样移动光标能够在凑出密码(每个串的光标位置表示一个密码的字 ...

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

    http://codeforces.com/contest/761/problem/B 题意: 有一个长度为l的环形跑道,跑道上有n个障碍,现在有2个人,给出他们每过多少米碰到障碍,判断他们跑的是不是 ...

随机推荐

  1. ORM多表操作上

    一.创建模型 例:我们来假定下面这些概念,字段和关系 作者模型:一个作者有姓名和年龄. 作者详细模型:把作者的详情放到详情表,包含生日,手机号,家庭住址等信息.作者详情模型和作者模型之间是一对一(on ...

  2. B/S选择文件夹上传

    1 背景 用户本地有一份txt或者csv文件,无论是从业务数据库导出.还是其他途径获取,当需要使用蚂蚁的大数据分析工具进行数据加工.挖掘和共创应用的时候,首先要将本地文件上传至ODPS,普通的小文件通 ...

  3. easyui的datagrid里getSelections只能获取一行值???

    使用getSelections只能获取到一行的值,检查了半天是因为idField属性值写错,更正之后ok. 解决办法二:改为使用getChecked,idField写错无影响, 注: getSelec ...

  4. 添加对象到 HashSet 里的规则是

    下面的解释取自百度知道的一位网友的回答,链接如下: java HashSet类添加元素的问题_百度知道http://zhidao.baidu.com/link?url=9bcAnolev1EBeFI_ ...

  5. PHP垃圾回收深入理解

    转摘于http://www.cnblogs.com/lovehappying/p/3679356.html PHP是一门托管型语言,在PHP编程中程序员不需要手工处理内存资源的分配与释放(使用C编写P ...

  6. PHP-图片处理

    开启 GD 扩展(php_gd2.dll) 创建画布 画布:一种资源型数据,可以操作的图像资源. 创建新画布(新建) ImageCreate(宽,高); 创建基于调色板的画布. imageCreate ...

  7. 【SQL SERVER】常见问题

    [账户] 偷懒默认安装了全部默认功能到虚拟服务器上,所以并没有设置sa账户的过程,自然只能从windows身份验证进入数据库.于是还得自己来为sa账户添加登陆权限. 步骤如下: 1. windows身 ...

  8. android handler 调用原理

    1,调度原理 andriod提供了Handler 和 Looper 来满足线程间的通信.Handler先进先出原则.Looper类用来管理特定线程内对象之间的消息交换(MessageExchange) ...

  9. node进程一些信号的意义

    1.SIGINT这个信号是系统默认信号,代表信号中断,就是ctrl+c: 2.SIGQUIT 3.SIGTERM 4.exit

  10. python安装numpy

    命令介绍: D:\computerSoft\python3.6.4\Scripts>python36 pip3.6.exe install numpy # 通过pip下载对应版本的numpy,然 ...