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, ...
随机推荐
- HDU-1034 Candy Sharing Game 模拟问题(水题)
题目链接:https://cn.vjudge.net/problem/HDU-1034 水题 代码 #include <cstdio> #include <algorithm> ...
- BZOJ 4373算术天才⑨与等差数列(线段树)
题意:给你一个长度为n的序列,有m个操作,写一个程序支持以下两个操作: 1. 修改一个值 2. 给出三个数l,r,k, 询问:如果把区间[l,r]的数从小到大排序,能否形成公差为k的等差数列. n,m ...
- vSphere VCSA5.5加入AD域环境问题记录
vSphere VCSA5.5加入AD域环境问题记录 实验目的: 搭建一套vSphere VCSA5.5,并加入新搭建的AD域,并使用一个域用户登录VC,赋予对VC的只读权限. 实验环境: 使用VMW ...
- 洛谷 P1754 球迷购票问题
P1754 球迷购票问题 题目背景 盛况空前的足球赛即将举行.球赛门票售票处排起了球迷购票长龙. 按售票处规定,每位购票者限购一张门票,且每张票售价为50元.在排成长龙的球迷中有N个人手持面值50元的 ...
- DMA在FPGA的应用之我见
首先,来做一个简单的实验,利用DMA来实现on-chip-memory和SRAM之间的传输,同时也在做一个关于SRAM不同地址之间的传输. 一.硬件设计 1.首先设计自己的SOPC结构,包括CPU.j ...
- .net core的安装
安装完成后的路径在C:\Program Files\dotnet https://github.com/dotnet/cli/issues/390 ===2017年06月29日=== 安装成功之后,配 ...
- Android控件-TabHost(一)
什么是TabHost? TabHost组件的主要功能是可以进行应用程序分类管理,例如:在用户使用windows操作系统的时候,经常见到如图所示的图形界面. TabHost选项卡,说到这个组件, ...
- How Javascript works (Javascript工作原理) (十一) 渲染引擎及性能优化小技巧
个人总结:读完这篇文章需要20分钟,这篇文章主要讲解了浏览器中引擎的渲染机制. DOMtree ----| |----> RenderTree CSSOMtree ----| ...
- nuxt 关闭ESlint 语法检测
学习nuxt中在自己编写search组件的时候出现了各种类似于Expected indentation of 0 spaces but found 4的问题 上网搜是因为ESlint语法检测产生的问题 ...
- Python基础班培训视频课程
课程目录:│ ├─第01天视频│ │ 01-课程介绍.avi│ │ 02-什么是操作系统.avi│ │ 03-生活中的操作系统.avi│ │ 04-操 ...