Clock Pictures

Time Limit: 1000ms
Memory Limit: 524288KB

This problem will be judged on CodeForcesGym. Original ID: 100502H
64-bit integer IO format: %I64d      Java class name: (Any)

You have two pictures of an unusual kind of clock. The clock has n hands, each having the same length and no kind of marking whatsoever. Also, the numbers on the clock are so faded that you can’t even tell anymore what direction is up in the picture. So the only thing that you see on the pictures, are n shades of the n hands, and nothing else.

You’d like to know if both images might have been taken at exactly the same time of the day, possibly with the camera rotated at different angles.

Task

Given the description of the two images, determine whether it is possible that these two pictures could be showing the same clock displaying the same time.

Input

The first line contains a single integer n (2 ≤ n ≤ 200000), the number of hands on the clock.

Each of the next two lines contains n integers ai (0 ≤ ai < 360000), representing the angles of the hands of the clock on one of the images, in thousandths of a degree. The first line represents the position of the hands on the first image, whereas the second line corresponds to the second image. The number ai denotes the angle between the recorded position of some hand and the upward direction in the image, measured clockwise. Angles of the same clock are distinct and are not given in any specific order.

Output

Output one line containing one word: possible if the clocks could be showing the same time, impossible otherwise.

Figure H.1: Sample input 2

Sample Input 1                                                      Sample Output 1

6

1 2 3 4 5 6

7 6 5 4 3 1

impossible

Sample Input 2                                                      Sample
Output 2

2

0 270000

180000
270000

possible

Sample Input 3                                                      Sample Output 3

7

140 130
110 120 125 100 105

235 205
215 220 225 200 240

impossible

NCPC
2014 Problem H: Clock Pictures

解题:直接用kmp...

 #include <bits/stdc++.h>
using namespace std;
const int maxn = ,mod = ;
int fail[maxn],a[maxn],b[maxn],c[maxn<<],n;
void getNext(){
fail[] = fail[] = ;
for(int i = ; i < n; ++i){
int j = fail[i];
while(j && a[i] != a[j]) j = fail[j];
fail[i + ] = a[i] == a[j]?j+:;
}
}
int main() {
while(~scanf("%d",&n)) {
for(int i = ; i < n; ++i)
scanf("%d",a+i);
for(int i = ; i < n; ++i)
scanf("%d",b+i);
sort(a,a+n);
sort(b,b+n);
c[n-] = (b[] - b[n - ] + mod)%mod;
for(int i = ; i < n; ++i){
a[i-] = (a[i] - a[i-] + mod)%mod;
b[i-] = (b[i] - b[i-] + mod)%mod;
c[i - ] = c[i + n - ] = b[i - ];
}
getNext();
bool flag = false;
for(int i = ,j = ; i < (n<<)-; ++i){
while(j && a[j] != c[i]) j = fail[j];
if(a[j] == c[i]) j++;
if(j == n-){
flag = true;
break;
}
}
puts(flag?"possible":"impossible");
}
return ;
}
/*
6
1 2 3 4 5 6
7 6 5 4 3 1 2
0 270000
180000 270000 7
140 130 110 120 125 100 105
235 205 215 220 225 200 240
*/

CodeForcesGym 100502H Clock Pictures的更多相关文章

  1. 修改Linux系统日期与时间date clock

    先设置日期 date -s 20080103 再设置时间 date -s 18:24:30 为了永久生效,需要将修改的时间写入CMOS. 查看CMOS的时间: #clock -r 将当前系统时间写到C ...

  2. 操作系统页面置换算法(opt,lru,fifo,clock)实现

    选择调出页面的算法就称为页面置换算法.好的页面置换算法应有较低的页面更换频率,也就是说,应将以后不会再访问或者以后较长时间内不会再访问的页面先调出. 常见的置换算法有以下四种(以下来自操作系统课本). ...

  3. Cesium应用篇:3控件(1)Clock

    创建 跟Clock相关的主要有Animation控件和Timeline控件,通常两者会放在一起使用. 在Cesium中,Viewer默认开启这两个控件,如果你想要不显示控件,可以在Viewer初始化中 ...

  4. get back to the slower clock rate that allows it to save more power

    http://www.howtogeek.com/177790/why-you-cant-use-cpu-clock-speed-to-compare-computer-performance/ Wh ...

  5. Clock rate

    https://en.wikipedia.org/wiki/Clock_rate The clock rate typically refers to the frequency at which a ...

  6. clock()、time()、clock_gettime()和gettimeofday()函数的用法和区别【转】

    转自:http://www.cnblogs.com/krythur/archive/2013/02/25/2932647.html 转自http://blog.sina.com.cn/s/blog_7 ...

  7. 最少clock

    var elClock = document.getElementById("clock");var getTime = function(){ var _ = ['00','01 ...

  8. 用clock()函数计算多项式的运行时间

    百度百科中定义clock():clock()是C/C++中的计时函数,而与其相关的数据类型是clock_t.在MSDN中,查得对clock函数定义如下: clock_t clock(void) ; 简 ...

  9. 编写Java应用程序。首先,定义一个时钟类——Clock,它包括三个int型 成员变量分别表示时、分、秒,一个构造方法用于对三个成员变量(时、分、秒) 进行初始化,还有一个成员方法show()用于显示时钟对象的时间。其次,再定义 一个主类——TestClass,在主类的main方法中创建多个时钟类的对象,使用这 些对象调用方法show()来显示时钟的时间。

    package com.hanqi.test; public class Clock { int hh; int mm; int ss; String time; Clock(int h,int m, ...

随机推荐

  1. bzoj1270 BeijingWc2008 雷涛的小猫 DP

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1270 比较水的一道dp f1[i]为高度为i的时候的最大值 f2[i]为当前高度在第i棵树 ...

  2. python 任何基础问题,包括语法等

    *)copy()和deep copy() 参考链接:https://blog.csdn.net/qq_32907349/article/details/52190796 *)OPP面向对象编程 *)接 ...

  3. 题解 P1531 【I Hate It】

    这道题明明是裸的线段树,蒟蒻却80分了五六次... ------------ 根据题意,显然是维护一棵单点修改区间查询的线段树,于是直接套区间修改的代码... 结构体,即为树上的节点. struct ...

  4. 去掉vs2010字符串下红色波浪线

    由于在vs集成了qt库,无法提升代码. 所以下载了visual assist,然后新的问题出现了,凡是在vs中输入的字符串,下面都有红色的波浪线,而且没有错误,只是看着不舒服. 解决方法: 在VAss ...

  5. Map和Collection详解

    Collection     -----List                -----LinkedList    非同步                 ----ArrayList      非同 ...

  6. Hadoop2 伪分布式部署

    一.简单介绍 二.安装部署 三.执行hadoop样例并測试部署环境 四.注意的地方 一.简单介绍 Hadoop是一个由Apache基金会所开发的分布式系统基础架构,Hadoop的框架最核心的设计就是: ...

  7. java音乐播放之IO流处理

    这个类仅仅能一直播放.知道音乐结束. 比AudioCilp要好一点. import java.io.*; import javax.sound.sampled.*; public class Test ...

  8. 逆波兰表达式解数学运算(c#)

    逆波兰表达式解数学运算 感谢作者 http://blog.csdn.net/liuyuxusuixiang/article/details/25289715 public class TCalcula ...

  9. python 写了一个批量拉取文件进excel文档

    路径如: C:\\Users\\huaqi\\Desktop\\信息收集 “信息收集”目录下有以下子目录:[技术,客服,运营,行政] “技术”目录下有以下子文件:[小白.txt,小红.txt,小黑.t ...

  10. 今日SGU 5.23

    SGU 223 题意:给你n*n的矩形,放k个国王,每个国王不能放在别的国王的8连边上,问你有多少种方法 收获:状态DP,因为每行的放置只会影响下一行,然我们就枚举每行的状态和对应的下一行的状态,当两 ...