Codeforces Round #394 (Div. 2) - B
题目链接: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的更多相关文章
- 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) 颓废记
昨天晚上(今天凌晨),又忍不住去打CF.(本蒟弱到只能打Div.2)... 我觉得我可以用一个词概括我这次的CF: 呵呵 刚一开赛,我就codeforces访问失败.. 后来好不容易能上了,两三分钟才 ...
- 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) 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 暴力
B. Dasha and friends 题目连接: http://codeforces.com/contest/761/problem/B Description Running with barr ...
- 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) E. Dasha and Puzzle(dfs)
http://codeforces.com/contest/761/problem/E 题意:给出一棵树,现在要把这棵树上的结点放置在笛卡尔坐标上,使得每一条边与x轴平行或者与y轴平行.输出可行解,即 ...
- Codeforces Round #394 (Div. 2) C.Dasha and Password(暴力)
http://codeforces.com/contest/761/problem/C 题意:给出n个串,每个串的初始光标都位于0(列)处,怎样移动光标能够在凑出密码(每个串的光标位置表示一个密码的字 ...
- Codeforces Round #394 (Div. 2) B. Dasha and friends(暴力)
http://codeforces.com/contest/761/problem/B 题意: 有一个长度为l的环形跑道,跑道上有n个障碍,现在有2个人,给出他们每过多少米碰到障碍,判断他们跑的是不是 ...
随机推荐
- VUE的系统指令
1. -text原样渲染,渲染文本 2.-html HTML渲染页面 举例: <!doctype html> <html lang="en"> < ...
- Python随笔——Map之键对应多值的处理
在使用 Python 处理时,因为某些原因,可能遇到 Map 的键对应多个值的处理. 很常见的比如:查询某表的结果,对应了多条记录. 此时使用Python进行算法处理时,其中一种方式如下: 定义一个 ...
- 一个KVO 实现WKWebView加载进度条的例子 (注意最后移除观察者)
// // OpenWebViewController.m // Treasure // // Created by 蓝蓝色信子 on 16/7/29. // Copyright © 2016年 GY ...
- Window10彻底卸载应用商店
Window10如何彻底卸载应用商店?Window10应用商店就是一个应用下载平台,我们可以在应用商店中下载各种应用,但是很多用户并不喜欢在Window10应用商店中下载应用,觉得应用商店浪费内存,因 ...
- 4412 使用usb摄像头拍照YUYV格式
一.内核设置 Linux内核中已经带有很完善的USB摄像头驱动,支持几乎所有的USB摄像头,我们只需要配置内核,选择上相应的Sensor型号即可. 配置内核,支持USB摄像头: Device Driv ...
- js点击获取—通过JS获取图片的绝对对坐标位置
一.通过JS获取鼠标点击时图片的相对坐标位置 源代码如下所示: <!DOCTYPE html> <html lang="en"> <head> ...
- python中的方法使用
#Python其实有3个方法,即静态方法(staticmethod),类方法(classmethod)和实例方法,如下: class Foo: def bar(self): # cls 是当前对象的实 ...
- ThreadPoolExecutor实现异步多线程
import time from concurrent.futures import ThreadPoolExecutor executor = ThreadPoolExecutor(max_work ...
- r_action
皮尔逊相关系数 斯皮尔曼等级相关(Spearman Rank Correlation) http://wiki.mbalib.com/wiki/斯皮尔曼等级相关 从表中的数字可以看出,工人的考试成绩愈 ...
- leetcode 20. 有效的括号 (python)
给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合.左括号必须以正确的顺序闭合.注意空字符串可被认为是 ...