CodeForcesGym 100502H Clock Pictures

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

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 200010,mod = 360000;
 4 int fail[maxn],a[maxn],b[maxn],c[maxn<<1],n;
 5 void getNext(){
 6     fail[0] = fail[1] = 0;
 7     for(int i = 1; i < n; ++i){
 8         int j = fail[i];
 9         while(j && a[i] != a[j]) j = fail[j];
10         fail[i + 1] = a[i] == a[j]?j+1:0;
11     }
12 }
13 int main() {
14     while(~scanf("%d",&n)) {
15         for(int i = 0; i < n; ++i)
16             scanf("%d",a+i);
17         for(int i = 0; i < n; ++i)
18             scanf("%d",b+i);
19         sort(a,a+n);
20         sort(b,b+n);
21         c[n-1] = (b[0] - b[n - 1] + mod)%mod;
22         for(int i = 1; i < n; ++i){
23             a[i-1] = (a[i] - a[i-1] + mod)%mod;
24             b[i-1] = (b[i] - b[i-1] + mod)%mod;
25             c[i - 1] = c[i + n - 1] = b[i - 1];
26         }
27         getNext();
28         bool flag = false;
29         for(int i = 0,j = 0; i < (n<<1)-1; ++i){
30             while(j && a[j] != c[i]) j = fail[j];
31             if(a[j] == c[i]) j++;
32             if(j == n-1){
33                 flag = true;
34                 break;
35             }
36         }
37         puts(flag?"possible":"impossible");
38     }
39     return 0;
40 }
41 /*
42 6
43 1 2 3 4 5 6
44 7 6 5 4 3 1
45
46 2
47 0 270000
48 180000 270000
49
50 7
51 140 130 110 120 125 100 105
52 235 205 215 220 225 200 240
53 */

时间: 2024-10-13 23:11:42

CodeForcesGym 100502H Clock Pictures的相关文章

HDU 4256 The Famous Clock

The Famous Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1399    Accepted Submission(s): 940 Problem Description Mr. B, Mr. G and Mr. M are now in Warsaw, Poland, for the 2012's ACM-ICPC

Clock Pictures

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 i

时间管理命令date、clock、hwclock

date:日期 1.命令作用: 显示或设置系统时间和日期,需要特别说明的是,只有超级用户才能用date命令设置时间,一般用户只能用date命令显示时间. 2.使用方式: date [options] [+格式] 3.参数说明: -d<字符串>:显示字符串所指的日期与时间.字符串前后必须加上双引号. -s<字符串>:根据字符串来设置日期与时间.字符串前后必须加上双引号. -u:显示GMT. %y 年份(以00-99来表示). %Y 年份(以四位数来表示). %m 月份(以01-12来

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

package com.homework.zw; public class Clock { String hour; String minute; String second; Clock(String h,String m, String s) { hour=h; minute=m; second=s; } void show() { System.out.println("时间为:"+hour+"时"+minute+"分"+second+&q

hdu5387 Clock(数学水题)

题目: Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 709    Accepted Submission(s): 452 Problem Description Give a time.(hh:mm:ss),you should answer the angle between any two of the minute

HDU 多校 VIII 1008 clock

Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 377    Accepted Submission(s): 200 Problem Description Give a time.(hh:mm:ss),you should answer the angle between any two of the minute.hou

QDemo - Analog clock模拟时钟学习并改进

调用函数setRenderHint(QPainter::Antialiasing,true),使绘制时边缘平滑,使用颜色浓度的变化,把图形的边缘转换为象素时引起的扭曲变形尽可能减少,在支持这一功能的平台或者绘图设备上得到一个平滑的边缘. QTimer类提供了定时器信号和单触发定时器. 它在内部使用定时器事件来提供更通用的定时器.QTimer很容易使用:创建一个QTimer,使用start()来开始并且把它的timeout()连接到适当的槽.当这段时间过去了,它将会发射timeout()信号. 我

Guidelines for clock

1 Avoid mixed clock edges Guideline 01 Avoid using both positive-edge and negative-edge triggered flip-flops. If must use both positive-edge and negative-edge triggered flip-flops, then 1) model the worst-case duty cycle of the clock accurately in sy

hone hone clock人体时钟

hone hone clock是个十分有趣的人体时钟,这个时钟代码分两种一种是背景透明的,一种 是白色背景的,把你喜欢的代码添加到你的网页中适当位置即可.两种代码如下: <script charset="Shift_JIS" src="http://chabudai.sakura.ne.jp/blogparts/honehoneclock/honehone_clock_tr.js"></script> 或 <script charset