CodeForcesGym 100502H Clock Pictures
2015-04-27 19:46
716 查看
Clock Pictures
Time Limit: 1000msMemory 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.#include <bits/stdc++.h> using namespace std; const int maxn = 200010,mod = 360000; int fail[maxn],a[maxn],b[maxn],c[maxn<<1],n; void getNext(){ fail[0] = fail[1] = 0; for(int i = 1; i < n; ++i){ int j = fail[i]; while(j && a[i] != a[j]) j = fail[j]; fail[i + 1] = a[i] == a[j]?j+1:0; } } int main() { while(~scanf("%d",&n)) { for(int i = 0; i < n; ++i) scanf("%d",a+i); for(int i = 0; i < n; ++i) scanf("%d",b+i); sort(a,a+n); sort(b,b+n); c[n-1] = (b[0] - b[n - 1] + mod)%mod; for(int i = 1; i < n; ++i){ a[i-1] = (a[i] - a[i-1] + mod)%mod; b[i-1] = (b[i] - b[i-1] + mod)%mod; c[i - 1] = c[i + n - 1] = b[i - 1]; } getNext(); bool flag = false; for(int i = 0,j = 0; i < (n<<1)-1; ++i){ while(j && a[j] != c[i]) j = fail[j]; if(a[j] == c[i]) j++; if(j == n-1){ flag = true; break; } } puts(flag?"possible":"impossible"); } return 0; } /* 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 */
View Code
相关文章推荐
- Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉
- 【模拟】BAPC2014 G Growling Gears (Codeforces GYM 100526)
- 【模拟】NEERC15 E Easy Problemset (2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- CodeForces Gym 100685E Epic Fail of a Genie (贪心,控制精度)
- Codeforces Gym 100825 B. Delete This! (枚举 + 三分)
- CodeForcesGym 100676G Training Camp
- Codeforces Gym - 101128C Canvas Painting [想法]
- CodeForces Gym 100187 A Potion of Immortality
- Codeforces Gym 100548H The Problem to Make You Happy (图上博弈DP)
- CodeForcesGym 100212E Long Dominoes
- UVA Live 7958 (Codeforces Gym 101201G) Maximum Islands 二分图染色+匹配
- CodeForcesGym 100733D Little thief Shi
- codeforces gym 100357 J (网络流)
- Codeforces Gym 101164I Cubes
- CodeForces Gym 100989J Objects Panel (A)
- CodeForces Gym 100735E
- codeforces GYM 100781A【树的直径】
- Codeforces Gym 100803G Flipping Parentheses 线段树+二分
- Codeforces Gym 101190 (NEERC 2016) E. Expect to Wait (扫描线)
- codeforces Gym 100187B B. A Lot of Joy