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个人,给出他们每过多少米碰到障碍,判断他们跑的是不是 ...
随机推荐
- Task10.Bert
Transformer原理 论文地址:Attention Is All You Need:https://arxiv.org/abs/1706.03762 Transformer是一种完全基于Atte ...
- mysql 1067 - Invalid default value for 'addtime'错误处理
错误描述 TABLE `bota_payment_closing` ( `id` int(11) NOT NULL AUTO_INCREMENT, `monthly` varchar(8) NOT N ...
- sql select语句详解
先group by 后 order by SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ] * | expression [ AS ...
- Linux shell - scp命令用法
例子: 远程复制一个文件从服务器A (172.0.0.0) /home/test/file1.txt 到 服务器B (172.0.0.1) /home/test 服务器A和服务器B的用户是 test ...
- 牛客:t次询问,每次给你一个数n,求在[1,n]内约数个数最多的数的约数个数(数论+贪心)
https://ac.nowcoder.com/acm/contest/907/B t次询问,每次给你一个数n,求在[1,n]内约数个数最多的数的约数个数 分析: 根据约数和定理:对于一个大于1正整数 ...
- IHttpHandler
https://docs.microsoft.com/en-us/dotnet/api/system.web.ihttphandler?view=netframework-4.8 Defines th ...
- http://research.google.com/archive/mapreduce.html
http://research.google.com/archive/mapreduce.html
- Eclipse报内存溢出
(1)在配置tomcat的JDK里面设置.Window-->proference->Myeclipse-->servers-->Tomcat5-->JDK里面设置: -X ...
- Linux_自制系统服务启动脚本
目录 目录 前言 Case语句 Apache 启动脚本 Postfix service 启停脚本 前言 在Linux的某些系统服务中,需要自己定制启动服务的脚本.通常会使用Cash语句来实现. Cas ...
- instanceof关键字用于判断一个引用类型变量所指向的对象是否是一个类(或接口、抽象类、父类)的实例。
http://lavasoft.blog.51cto.com/62575/79864/ 深入Java关键字instanceof 2008-06-02 07:50:43 标签:Java 关键字 休 ...