题目链接: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. hdu 4992 Primitive Roots 【求原根模板】

    题目链接 大题流程: 判定是否有原根->求出最小原根->利用最小原根找出全部原根 #include<bits/stdc++.h> using namespace std; ty ...

  2. vue兄弟组件之前传信

    1.使用vuex 2.子传父,父传子 3.使用中央事件总线 1.新建一个js文件,然后引入vue 实例化vue 最后暴露这个实例 2.在要用的组件内引入这个组件 3.通过vueEmit.$emit(' ...

  3. 对Promise的研究4

    Promise.reject() Promise.reject(reason)方法也会返回一个新的 Promise 实例,该实例的状态为rejected. const p = Promise.reje ...

  4. char* 和 cha[]

    char* s1 = "hello";//字符串常量 s是一个保存了字符串首地址的指针变量,同时也是字符串的名字,s的内容是第一个字符的地址,当s指向常量字符串时候,内容不能改变( ...

  5. UE4使用Dll

    Part1. 创建和编译Dll VS中创建Visual C++ > Win32 Console Application 工程模板,选择Dll,并勾上”Empty Project”. 在Solut ...

  6. LintCode之合并排序数组II

    题目描述: 分析:题目的意思是把数组A和数组B合并到数组A中,且数组A有足够的空间容纳A和B的元素,合并后的数组依然是有序的. 我的代码: public class Solution { /* * @ ...

  7. xiugai完了

    <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...

  8. leetcode 189. 旋转数组(python)

    给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数. 示例 1: 输入: [1,2,3,4,5,6,7] 和 k = 3输出: [5,6,7,1,2,3,4]解释:向右旋转 1 步: ...

  9. gitlab+jenkins自动化打包IOS-jenkins配置

    实现的效果如图:  构建界面: 完成效果: 功能说明: 根据选择的代码分支,执行构建打包 构建成功后根据ipa/apk生成二维码,并可在历史构建列表中展示各个版本的二维码,通过手机扫描二维码可直接安装 ...

  10. npm install 安装过程卡住不动

    修改 npm 的安装目录下的 npmrc文件 增加一条 registry=http://registry.cnpmjs.org $ npm config set registry http://reg ...