CodeForcesGym 100502H Clock Pictures
Clock Pictures
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 |
possible |
Sample Input 3 Sample Output 3
|
7 140 130 235 205 |
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的更多相关文章
- 修改Linux系统日期与时间date clock
先设置日期 date -s 20080103 再设置时间 date -s 18:24:30 为了永久生效,需要将修改的时间写入CMOS. 查看CMOS的时间: #clock -r 将当前系统时间写到C ...
- 操作系统页面置换算法(opt,lru,fifo,clock)实现
选择调出页面的算法就称为页面置换算法.好的页面置换算法应有较低的页面更换频率,也就是说,应将以后不会再访问或者以后较长时间内不会再访问的页面先调出. 常见的置换算法有以下四种(以下来自操作系统课本). ...
- Cesium应用篇:3控件(1)Clock
创建 跟Clock相关的主要有Animation控件和Timeline控件,通常两者会放在一起使用. 在Cesium中,Viewer默认开启这两个控件,如果你想要不显示控件,可以在Viewer初始化中 ...
- 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 ...
- Clock rate
https://en.wikipedia.org/wiki/Clock_rate The clock rate typically refers to the frequency at which a ...
- clock()、time()、clock_gettime()和gettimeofday()函数的用法和区别【转】
转自:http://www.cnblogs.com/krythur/archive/2013/02/25/2932647.html 转自http://blog.sina.com.cn/s/blog_7 ...
- 最少clock
var elClock = document.getElementById("clock");var getTime = function(){ var _ = ['00','01 ...
- 用clock()函数计算多项式的运行时间
百度百科中定义clock():clock()是C/C++中的计时函数,而与其相关的数据类型是clock_t.在MSDN中,查得对clock函数定义如下: clock_t clock(void) ; 简 ...
- 编写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, ...
随机推荐
- PKU 3281 Dining 网络流 (抄模板)
题意: 农夫约翰为他的牛准备了F种食物和D种饮料.每头牛都有各自喜欢的食物和饮料,而每种食物或饮料只能分配给一头牛.最多能有多少头牛可以同时得到各自喜欢的食物和饮料? 思路: 用 s -> 食物 ...
- python中的装饰器decorator
python中的装饰器 装饰器是为了解决以下描述的问题而产生的方法 我们在已有的函数代码的基础上,想要动态的为这个函数增加功能而又不改变原函数的代码 例如有三个函数: def f1(x): retur ...
- Spring Tool Suit安装virgo server插件、virgo的下载
virgo-tomcat原先是Spring DM Server,后来转eclipse社区维护 安装教程:http://osgi.com.cn/article/7289514 virgo-tomcat各 ...
- [Spark源代码剖析] DAGScheduler提交stage
转载请标明出处:http://blog.csdn.net/bigbigdata/article/details/47310657 DAGScheduler通过调用submitStage来提交stage ...
- vector和list容器之间的复制
#include <iostream> #include <list> #include <string> #include <vector> #inc ...
- URAL 1823. Ideal Gas(数学啊 )
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1823 1823. Ideal Gas Time limit: 0.5 second Me ...
- 在Maven项目中关于SSM框架中邮箱验证登陆
1.你如果要在maven项目中进行邮箱邮箱验证,你首先要先到pom.xml文件中配置mail.jar,activation.jar包 <dependency> <groupId> ...
- 火狐浏览器设置bypass
http://blog.sina.com.cn/s/blog_6f7d179e0101a60l.html 某个网段不使用代理的设置FF和IE不同,IE是用*通配符,FF是用CIDR的表示法, FF的简 ...
- CSS元素选择器 element selector(type selector)
http://www.w3school.com.cn/css/css_selector_type.asp 元素选择器 最常见的 CSS 选择器是元素选择器.换句话说,文档的元素就是最基本的选择器. 如 ...
- hight charts
hight charts http://www.hcharts.cn/resource/index.php http://www.hcharts.cn/api/index.php