Problem: ioi10_a
Categories: search
Difficulty: easy
Time limit: 1000 ms | Memory limit: 256 MB

Dr. Black has been murdered. Detective Jill must determine the murderer, the location, and the weapon. There are six possible murderers, numbered 1 to 6. There are ten possible locations, numbered 1 to 10. There are six possible weapons, numbered 1 to 6.

For illustration only, we show the names of the possible murderers, locations and weapons. The names are not required to solve the task.

|  |  |  |
| --- | --- | --- |
| Murderer | Location | Weapon |
| 1. Professor Plum 2. Miss Scarlet 3. Colonel Mustard 4. Mrs. White 5. Reverend Green 6. Mrs. Peacock  — | 1. Ballroom 2. Kitchen 3. Conservatory 4. Dining Room 5. Billiard Room 6. Library 7. Lounge 8. Hall 9. Study 10. Cellar   — | 1. Lead pipe 2. Dagger 3. Candlestick 4. Revolver 5. Rope 6. Spanner   — |

Jill repeatedly tries to guess the correct combination of murderer, location and weapon. Each guess is called a theory. She asks her assistant Jack to confirm or to refute each theory in turn. When Jack confirms a theory, Jill is done. When Jack refutes a theory, he reports to Jill that one of the murderer, location or weapon is wrong.

You are to implement the procedure Solve that plays Jill's role. The grader will call Solve many times, each time with a new case to be solved. Solve must repeatedly call Theory(M,L,W), which is implemented by the grader. M, L and W are numbers denoting a particular combination of murderer, location and weapon. Theory(M,L,W) returns 0 if the theory is correct. If the theory is wrong, a value of 1, 2 or 3 is returned. 1 indicates that the murderer is wrong; 2 indicates that the location is wrong; 3 indicates that the weapon is wrong. If more than one is wrong, Jack picks one arbitrarily between the wrong ones (not necessarily in a deterministic way). When Theory(M,L,W) returns 0, Solve should return.

Example

As example, assume that Miss Scarlet committed the murder (Murderer 2) in the conservatory (Location 3) using a revolver (Weapon 4). When procedure Solve makes the following calls to function Theory, the results in the second column could be returned.

|  |  |  |
| --- | --- | --- |
| Call | Returned value | Explanation |
| Theory(1, 1, 1) | 1, or 2, or 3 | All three are wrong |
| Theory(3, 3, 3) | 1, or 3 | Only the location is correct |
| Theory(5, 3, 4) | 1 | Only the murderer is wrong |
| Theory(2, 3, 4) | 0 | All are correct |

Scoring

|  |  |  |
| --- | --- | --- |
| Subtask | Points | Additional Input Constraints |
| 1 | 50 | Each test run may call Solve up to $100$ times. Each call might correspond to a different combination of murderer, location and weapon as the answer. Each time Solve is called, it must find the correct theory with no more than $360$ calls to Theory(M,L,W). Be sure to initialize any variables used by Solve every time it is called. |
| 2 | 50 | Each test run may call Solve up to $100$ times. Each time Solve is called, it must find the correct theory with no more than $20$ calls to Theory(M,L,W). Be sure to initialize any variables used by Solve every time it is called. |

Interactor / grader files:
cluedo.cpp: #include "grader.h"
#include "cluedo.h"

void Solve(){
   int r;
   r = Theory(1,2,3);
   if (r == 0) return;
   r = Theory(3,2,1);
   if (r == 0) return;
   r = Theory(4,4,4);
   if (r == 0) return;
}

grader.cpp: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "grader.h"
#include "cluedo.h"

static int M,L,W,gotit,cnt,maxcnt;

int Theory(int m, int l, int w) {
   ++cnt;
   if (m < 1 || m > 6 || l < 1 || l > 10 || w < 1 || w > 6) exit(92);
   if (rand()%2 && m != M) return 1;
   else if (rand()%2 && l != L) return 2;
   else if (rand()%2 && w != W) return 3;
   else if (m != M) return 1;
   else if (l != L) return 2;
   else if (w != W) return 3;
   gotit = 1;
   return 0;
}

int main(){
   while (3 == scanf("%d%d%d",&M,&L,&W)) {
      cnt = gotit = 0;
      Solve();
      if (cnt > maxcnt) maxcnt = cnt;
      if (!gotit) {
         printf("NO\n");
         return 91;
      }
   }
   printf("OK %d\n",maxcnt);
   return 0;
}

cluedo.h: void Solve();

grader.h: int Theory(int M, int L, int W);