Clock picturestime limit:1000msmemory limit:524288kbthis problem'll be judged onCodeforcesgym. Original id:100502h
64-bit integer IO format: %i64d Java class name: (any)
You have both pictures of an unusual kind of clock. The clock has n hands, each with the same length and no kind of marking whatsoever. Also, the numbers on the clock was so faded that's the can ' t even tell anymore what direction was up in the picture. So the-thing that's see on the pictures, is n shades of the n hands, and nothing else.
You ' d like to know if both images might has been taken at exactly the same time of the day, possibly with the camera rota Ted at different angles.
Task
Given the description of the images, determine whether it's possible that these the pictures could being showing the SAM e clock displaying the same time.
Input
The first line contains a single integer n (2≤ n ≤200000), and the number of hands on the clock.
Each of the next 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 in 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 is distinct and is not given on 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 Sampleoutput 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 |
NCPC2014 problem H:clock Pictures
Problem solving: Directly with KMP ...
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =200010, mod =360000;4 intfail[maxn],a[maxn],b[maxn],c[maxn<<1],n;5 voidGetNext () {6fail[0] = fail[1] =0;7 for(inti =1; I < n; ++i) {8 intj =Fail[i];9 while(j && a[i]! = a[j]) j =Fail[j];TenFail[i +1] = a[i] = = a[j]?j+1:0; One } A } - intMain () { - while(~SCANF ("%d",&N)) { the for(inti =0; I < n; ++i) -scanf"%d", A +i); - for(inti =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; A for(inti =1; I < n; ++i) { ata[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 (); - BOOLFlag =false; in for(inti =0, j =0; I < (n<<1)-1; ++i) { - while(j && a[j]! = c[i]) j =Fail[j]; to if(A[j] = = C[i]) J + +; + if(J = = n1){ -Flag =true; the Break; * } $ }Panax NotoginsengPuts (flag?)"possible":"Impossible"); - } the return 0; + } A /* the 6 + 1 2 3 4 5 6 - 7 6 5 4 3 1 $ $ 2 - 0 270000 - 180000 270000 the - 7Wuyi A. the 235 205 215 225 - */
View Code
Codeforcesgym 100502H Clock Pictures