[gcj] Re: Keep running in TIME_LIMIT_EXCEEDED on C

2018-04-06 Thread Stefan Djokovic
Thank you so much! I didn't even consider the problem was the fact that I 
wasn't using a new line in the printf, so much wasted time! D:

Thank you again! Gonna be super-careful next time

-- 
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 google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/bc828d63-d292-42e4-b689-06bc07d6ff41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[gcj] Re: Keep running in TIME_LIMIT_EXCEEDED on C

2018-03-30 Thread Xiongqi ZHANG
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 
#include 
#include 


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 google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
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.