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. 1、java面试

    1.为什么用单例而不用static 答案:首先你要明白static是在什么时候初始化的,其设计意图是什么,单例就是我们运行的当前虚拟机中有且只有一个需要的对象,不存在重复.static是给类静态成员变 ...

  2. 单尺度二维离散小波重构(逆变换)idwt2

    clc,clear all,close all; load woman; %单尺度二维离散小波分解.分解小波函数haar [cA,cH,cV,cD]=dwt2(X,'haar'); %单尺度二维离散小 ...

  3. [SOJ] 图的广度优先搜索

    Time Limit: 1sec    Memory Limit:256MB Description 读入图的邻接矩阵以及一个顶点的编号(图中顶点的编号为从1开始的连续正整数.顶点在邻接矩阵的行和列上 ...

  4. C#正则分组实例

    static void Main(string[] args) { string str = "大家家家家家家家明天天天天天天天天玩得得得得得得得开心"; Regex reg = ...

  5. 手机下的ev.pageX无效

      把  ev.pageX  换成  e.originalEvent.targetTouches[0].pageX;   例子: var start_x, start_y, end_x, end_y, ...

  6. 对象比较中 "相等性"和"同一性" 生动地解释

    对象们都住在不同的房间里,每个房间只能住一个对象.对象们都被锁在房间里,永远没有办法搬家(至少从我们讨论的角度来说,这个说法是正确的).所以如果你知道了一个对象的房间号,就能找到对应的对象. 现在假如 ...

  7. onbeforeunload与a标签在IE中的冲突bug(转载)

    onbeforeunload与a标签在IE中的冲突bug   onbeforeunload 是window的一个事件,目前Firefox,IE都支持,主要用来提示用户是否真的要离开该页面,通常在一些比 ...

  8. Html 嵌入 swf

    1. object + embed       传统的方法 优点:浏览器兼容性好,是 Macromedia 一直以来的官方方法缺点:a.embed 标签是不符合 W3C 的规范的,无法通过验证.当然, ...

  9. 设计模式4 外观模式 FACADE

    一个外观是一个类,其提供的功能介于工具箱的功能和完整系统的功能之间,并为一个包或者一个子系统中的类提供了简化的使用方式.

  10. 封装一个Ajax工具函数

    /*封装一个ajax工具函数*/ window.$ = {}; /*通过$定义一个ajax函数*/ /* * 1. type   string   请求的方式  默认是get * 2. url     ...