IOI2006 D0-2:THE FIFTH SUN

来源:互联网 发布:云豹手机直播系统源码 编辑:程序博客网 时间:2024/05/29 04:20

 IOI2006 D0-2

 

Fifth Country: Official Version
IOI’06 English
Practice – Task 2 Version 1.0
 
THE FIFTH SUN
Aztecs believed that every certain amount of days the sun was destroyed by a natural catastrophe
and was created again by the gods to start a new era. They called themselves the sons of the fifth
sun because they were sure that the sun had been destroyed four times before they were born as a tribe.
 
In the late years of their empire, Aztec priests came to the conclusion that history was cyclic, that is, there is a sequence E={e0,e1,…,en-1} of astrological events that will inevitably happen in order, one every day. After the sequence is finished, the world will be destroyed again.
 
Their conclusion was primarily based on the fact that the third and fourth suns lasted exactly n days each. They know this because the cultures that existed on the third and fourth suns leaved a record of the events that happened each day until their suns were destroyed.
 
When confronted with the fact that both sequences of events start differently, the priests defended
their theory arguing that the cyclic sequence of events can be rotated, that is, it can start anywhere,
so if the first event is ej, the sequence will continue {ej+1,ej+2,...,en-1,e0,e1,...,ej-1} until the n events are
completed.
 
According to Aztec chronology, the n-th day of the fifth sun is approaching, we need you to check
whether the sequences of the third and fourth suns are indeed the same only shifted.
Unfortunately, access to the sequences of the third and fourth suns is highly restricted. But the
libraries that own them have agreed to answer your questions regarding them. You can ask the
librarian for any two days of any of the suns, and he will tell you if the events of those two days
were the same or different.
 
TASK
Write a program that determines if the sequence of events of the fourth sun is indeed a rotation of
the sequence of events of the third sun. Your program must use the standard input and the
standard output for communicating with the librarian.
 
CONSTRAINTS
0 < n _ 25 000 000
 
INPUT AND OUTPUT
Your program must not read or write any files. Every interaction must be done using the standard
input and the standard output.
 
INTERACTION WITH THE LIBRARIAN
Your program can ask any of the following questions to the librarian. Each question must be
terminated by an end of line. Each answer will be terminated by an end of line.
 

QUESTION
ANSWER
Description
N
Length_of_sequences
Asks the librarian for the length of the sequences. The
librarian answers with a unique integer representing n
the number of days in both sequences.
E d1 s1 d2 s2
Comparision_result
0 -different events,
1 -same event,
2 -question contains
invalid data
Asks the librarian if the events of two days are the
same. The question consists of a character E followed
by four space separated integers. The first two
integers represent the day and sun of the first event,
the last two represent the day and sun of the second
event.
 

 

R r places
Values for r
0 –different,
1 –fourth sun
is a rotation
of third sun
Outputs the result found by your program. Consists of a character R followed by
two space separated integers, the first one represents the result, either a 0
(sequences are different) or a 1 (fourth sun is a rotation of third sun). The second
integer represents either the number of places the sequence of the fourth sun is
rotated to the right compared with the sequence of the third or a –1 if both
sequences are different.
Once your program outputs a result no more questions will be answered.
Your program must exit after printing the result.

 
 
 
SAMPLE INTERACTION
Suppose that n = 3 and that the events of the third sun can be represented by {IOI} where each
letter represents an event, and the events of the fourth sun can be represented by {IIO}. One
possible execution of your program is
 

QUESTION
ANSWER
Description
n
3
Indicates that the number of days in each sequence is 3
E 1 3 1 4
1
Indicates that the event on day 1 of the third sun and
day 1 of the fourth sun are equal.
E 2 3 2 4
0
Indicates that the event on day 2 of the third sun and
day 2 of the fourth sun are different.
E 4 3 2 4
2
The question contains invalid data. There isn’t a day 4
in the third sun
E 1 3 2 4 1
 
 
E 2 3 3 4 1
 
 
E 3 3 1 4 1
 
 
R 1 1
 
The sequences are the same. The value second
integer indicates that the sequence of the fourth sun is
shifted 1 place to the right compared with the sequence
of the third sun.

 
GRADING INFO
For one test case every test run will satisfy the following constraints
0 < n _ 1 000
 
 
原创粉丝点击