A game called Memory is played using A
to Y
(ASCII 65 to 89) printed on the face, so that each letter appears on exactly two cards. The cards are shuffled into some random order and dealt face down on the table.
Jack plays the game by turning two cards face up so the letters are visible. For each of the M
, he gets a candy. Regardless of whether the letters were equal or not, Jack then turns both cards face down again. The process is repeated until Jack receives
You are to implement a procedure play that plays the game. Your implementation should call the procedure faceup(C) which is implemented by the grader.
After every second call to faceup, the grader automatically turns both cards face down again.
Your procedure play may only terminate once Jack has received all
Example
The following is one possible sequence of calls your procedure play could make, with explanations.
Call | Returned value | Explanation |
---|---|---|
faceup( | B | Card |
faceup( | X | Card |
The grader automatically turns cards 1 and 7 face down. | ||
faceup( | X | Card |
faceup( | O | Card |
The grader automatically turns cards 7 and 15 face down. | ||
faceup( | X | Card |
faceup( | X | Card |
The grader automatically turns cards 50 and 7 face down. | ||
faceup( | X | Card |
faceup( | X | Card |
The grader automatically turns cards 7 and 50 face down. | ||
faceup( | B | Card |
... | ||
(some function calls were omitted) | ||
... | ||
faceup( | B | Card |
faceup( | B | Card |
Subtask 1 [50 points]
Implement any strategy that obeys the rules of the game and finishes it within the time limit.
For example, there is a simple strategy that always makes exactly
Subtask 2 [50 points]
Implement a strategy that finishes any possible game with at most
Implementation Details
- Implementation folder:
/home/ioi2010-contestant/memory/
(prototype: memory.zip) - To be implemented by contestant:
memory.c
ormemory.cpp
ormemory.pas
- Contestant interface:
memory.h
ormemory.pas
- Grader interface:
grader.h
orgraderlib.pas
- Sample grader:
grader.c
orgrader.cpp
orgrader.pas
andgraderlib.pas
- Sample grader input:
grader.in.1
.
Note: the input file contains one line with characters denoting the letters on the cards, in order, from to . - Expected output for sample grader input: if your implementation is correct, the output file will contain
OK n
where is the number of calls to faceup(C).
Comments