Task 1 - Chain | ||||
Chain of Atoms PROBLEM Scientists are investigating a special kind of molecule. It is known that the molecule consists of N different atoms, labeled from 1 to N, and the structure of the molecule is a linear chain. The scientists are equipped with a distance meter. At one time, this instrument can measure the distance between any two atoms in the molecule. The distance, reported by the instrument, is the absolute value of the difference of the two atom positions in the chain. If you access no atom for more than three times no damage is done to the molecule. If you access one or more atoms four times the molecule gets damaged. If you access one or more atoms five times the molecule gets destroyed. You are to write a program that discovers the complete structure of the molecule by determining the sequence of the atoms in the molecule. Figure 1 LIBRARY To operate the distance meter, you are given a library meter with three operations:
The dialogue between your program and the library procedures is logged in the text file chain.out. This log file also contains your answer and the error message in case of an error.
Instruction for Pascal programmers: include the import statement
in the source code. Instructions for C/C++ programmers: use the instruction
in the source code, create a project file chain.gpr in the task directory, add the files chain.c (chain.cpp) and meter.o into this project, and then compile and/or make your program. EXPERIMENTATION You can experiment with the library by creating a text file chain.in. The file must contain two lines. The first line should contain the integer N, the number of atoms. The second line should contain a test case: a sequence of the atom labels, consisting of N different integers between 1 and N. EXAMPLE FOR EXPERIMENTATION
CONSTRAINTS
GRADING If your answer is correct and no atom was accessed more than three times then you obtain full score. If your answer is correct but some atom was accessed four times then you obtain 50% of the scores. If the answer is incorrect or any atom was accessed five times, then you receive 0 score.
|