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. 隐藏div,文本框角圆滑,消除外边框

    #div_1 /*将div设置完成,并且隐藏,当需要的时候对其属性值进行修改*/ { height: 36px; width: 1099px; background-color: #F0DFDF; m ...

  2. yii2.0缓存篇之片段缓存

    片段缓存指的是缓存页面内容中的某个片段.默认缓存 60秒. return $this->renderPartial("ca");                        ...

  3. JS由Number与new Number的区别引发的思考

    在回答园子问题的时候发现了不少新东西,写下来分享一下 == 下面的图就是此篇的概览,另外文章的解释不包括ES6新增的Symbol,话说这货有包装类型,但是不能new... 基于JS是面向对象的,所以我 ...

  4. CF85E Guard Towers(二分答案+二分图)

    题意 已知 N 座塔的坐标,N≤5000 把它们分成两组,使得同组内的两座塔的曼哈顿距离最大值最小 在此前提下求出有多少种分组方案 mod 109+7 题解 二分答案 mid 曼哈顿距离 >mi ...

  5. java解析json文件(省,市,区)

    [{"code":"11","name":"北京市"},{"code":"12" ...

  6. caioj 1112 树形动态规划(TreeDP)7:战略游戏

    这道题和上一道题非常相似 这道题是看边,上一道是看点. 但是状态定义不同 看边的话没有不放不安全这种状态 因为当前结点的父亲无法让这颗子树没有看到的边看到 所以这种状态不存在 而上一道题存在不放不安全 ...

  7. 第四讲 Yang-Mills方程与Maxwell方程

    一.变分原理 变分原理始于17世纪的速降问题,也就是连接两点的曲线在有重力的情况下,让初速度为0的一小球最快地通过? 这个问题由伯努力给出解答,他的方法非常巧妙,而最后开创了一个学科——变分学.他假设 ...

  8. ECNUOJ 2616 游黄山

    游黄山 Time Limit:1000MS Memory Limit:65536KB Total Submit:165 Accepted:52 Special Judge Description Po ...

  9. 常量成员函数的注意事项 & mutable的使用场景

    mutable的使用场景: 可以在一个const的对象里面,解除对部分字段的const限制.也可以用在const成员函数里面. 对于const与否,一般会调用不同版本的函数: 而对于二元操作符,如果用 ...

  10. [React Native] Use the SafeAreaView Component in React Native for iPhone X Compatibility

    In this lesson, you will learn how to use the SafeAreaView component to avoid the sensor cluster (th ...