Clock Pictures

题目描述

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.
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.

输入

The first line contains a single integer n (2 ≤ n ≤ 200 000), the number of hands on the clock.
Each of the next two lines contains n integers a i (0 ≤ a i < 360 000), 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 a i 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 one line containing one word: possible if the clocks could be showing the same time,impossible otherwise.

样例输入

6
1 2 3 4 5 6
7 6 5 4 3 1

样例输出

impossible
分析:最小表示法或KMP;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <ctime>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define freopen freopen("in.txt","r",stdin)
const int maxn=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,len,a[maxn],b[maxn];
int getMin(int len,int str[]) {
int i = , j = ;
int l;
while (i < len && j < len) {
for (l = ; l < len; l++)
if (str[(i + l) % len] != str[(j + l) % len]) break;
if (l >= len) break;
if (str[(i + l) % len] > str[(j + l) % len]) {
if (i + l + > j) i = i + l + ;
else i = j + ;
}
else if (j + l + > i) j = j + l + ;
else j = i + ;
}
return i < j ? i : j;
}
int main()
{
int i,j;
scanf("%d",&n);
rep(i,,n-)scanf("%d",&a[i]);
rep(i,,n-)scanf("%d",&b[i]);
sort(a,a+n);
sort(b,b+n);
a[n]=a[],b[n]=b[];
rep(i,,n-)
{
a[i]=a[i+]-a[i];
b[i]=b[i+]-b[i];
if(i==n-)a[i]+=,b[i]+=;
}
int pos1=getMin(n,a),pos2=getMin(n,b);
for(int i=pos1,j=pos2,cnt=;cnt<n;cnt++,i++,j++)
{
if(i==n)i=;
if(j==n)j=;
if(a[i]!=b[j])return *puts("impossible");
}
puts("possible");
//system("Pause");
return ;
}

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, ...

  10. Clock Skew , Clock Uncertainty和 Period

    本文将介绍FPGA中和时钟有关的相关概念,阅读本文前需要对时序收敛的基本概念和建立.保持关系有一定了解,这些内容可以在时序收敛:基本概念,建立时间和保持时间(setup time 和 hold tim ...

随机推荐

  1. Haskell 函数式编程

    Haskell是纯函数式编程,它强调不函数不改变外部世界状态,即,一个函数的输出只由函数接收的输入决定.那如何与外面沟通呢,比如读取一个文件内容并输出这个文件内容(字符串),显然这种函数非纯函数,因为 ...

  2. Hoffmann树

    数据压缩编码 先把两棵二叉树简化成叶子结点带权的二叉树,图的每个结点之间带有权值 结点的路径长度: 从根结点到该结点的路径上的连接数. 树的路径长度: 树中每个叶子结点的路径长度之和. 结点带权路径长 ...

  3. Hanoi汉诺塔问题——递归与函数自调用算法

    题目描述 Description 有N个圆盘,依半径大小(半径都不同),自下而上套在A柱上,每次只允许移动最上面一个盘子到另外的柱子上去(除A柱外,还有B柱和C柱,开始时这两个柱子上无盘子),但绝不允 ...

  4. Openjudge-计算概论(A)-求分数序列和

    描述: 有一个分数序列 2/1,3/2,5/3,8/5,13/8,21/13,.... 求这个分数序列的前n项之和.输入输入有一行:正整数n.输出输出有一行:分数序列的和(浮点数,精确到小数点后4位) ...

  5. python读取bin文件并下发串口

    # coding:utf-8import time, serialfrom struct import *import binascii file = open('E:\\1.bin', 'rb')i ...

  6. redis数据类型:Strings

    String是最简单的数据类型,一个key对应一个value,string类型是二进制安全的,redis的String可以包含任何数据, 比如jpg图片或者系列化的对象. Set方法: 设置key对应 ...

  7. pgadmin3 新建服务器出现错误 Peer authentication failed for user "postgres" 的解决办法

    转自:http://blog.csdn.net/tingyuanss/article/details/43763899 用pgadmin3 新建服务器出现错误 Peer authentication ...

  8. Urbanization

    Urbanization time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  9. bootstrap开始咯

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...

  10. Struts2--课程笔记3

    获取ServletAPI: 第一种方式: //在request域中放入属性req,暂且认为getContext()获取的是request域空间,但实际不是        ActionContext.g ...