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, ...
随机推荐
- vue+element-ui的简洁导入导出功能
1.前段后台管理系统中数据展示一般都是用表格,表格会涉及到导入和导出;原生js导出excel2.导入是利用element-ui的Upload 上传组件; <el-upload class=&qu ...
- 【uva 1025】A Spy in the Metro
[题目链接]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- AJAX--XMLHttpRequest五步使使用方法
传统浏览方式和AJAX方式的不同 多数Web应用程序都使用请求/响应模型从server上获得完整的HTML页面.经常是点击一个button,等待server对应,在点击还有一个button.然后在等待 ...
- C++ priority_queue的使用 & Java PriorityQueue
刚刚那道BST的题目,也用到了priority_queue,那是那个没有定义比较函数. 那么下面这个,就要定义比较函数. 它的模板声明带有三个参数,priority_queue<Type, Co ...
- 用C3P0建立server与数据库的连接
1:在MyEclipse建立 Web Service Project 2:在project中建立servlets包 3:在包中新建Servlet文件(採用new Servlet方法可省去配置web.x ...
- [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 ...
- HTML <button> 标签
HTML <button> 标签 目标 实现点击button跳转到一个新的界面 参考文档 实例 以下代码标记一个按钮: <button type="button" ...
- Chromium Graphics: HW Video Acceleration in Chrom{e,ium}{,OS}
HW Video Acceleration in Chrom{e,ium}{,OS} Ami Fischman <fischman@chromium.org> Status as of 2 ...
- @Accessors
@Accessors 作用:存取器,用于配置getter和setter方法的生成结果 三个属性:fluent.chain.prefix 1.fluent:流畅的,设置为true,getter和sett ...
- python数据处理技巧二
python数据处理技巧二(掌控时间) 首先简单说下关于时间的介绍其中重点是时间戳的处理,时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00 ...