For each exchange, your program needs to use standard output to send a **single 
line** with one integer Q

I think the reason why you get TLE is that you need to print a newline for each 
Q you print.

Also, your make a typical mistake writing the binary search.

If the input is A = 3 and B = 4, and the correct answer is 4, your code will 
keep asking for Q = 3, and getting response that 3 is TOO_SMALL.


Here is the correct solution:

```C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main() {
        int T; //n cases
        int A, B; //lower exlusive bound, upper inclusive bound
        int N; //max number of guessing
        int Q; //my try
        char res[13];

        int i, k;

        scanf("%d", &T);

        for (i = 1; i <= T; i++) { //stops after T cases
                scanf("%d", &A);
                scanf("%d", &B);
                scanf("%d", &N);
                for (k = 0; k < N; k++) { //stops after N tries
                        Q = (B + A + 1) / 2; //gets the avarage between min,max
                        fflush(stdout); //random fflush 1
                        printf("%d\n", Q);
                        fflush(stdout); //random fflush 2
                        scanf("%s", res); //get the answer from the machine
                        if (res[4] == 'S') //TOO_SMALL
                                A = Q;
                        else if (res[4] == 'B') //TOO_BIG
                                B = Q - 1;
                        else if (res[4] == 'E') //CORRECT
                                k = N;
                        else if (res[4] == 'G') //WRONG_ANSWER
                                return 0;
                        else
                                k = N; //just in case to make the run end
                        fflush(stdout); //random fflush 3


                }
        }

        return 0;
}
```

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/52139ef2-fb44-453f-bc0e-12012988ac5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to