Page 1 of 2

C compiler

Posted: Mon Apr 17, 2006 1:11 pm
by C
I write following code to solve problem 10998, but i got "TL", and when I only change the input and output code to java code, and choose submit with java, it is accepted.Isn't it strange? Can anyone perhaps tell me what may be the error under C??

Code: Select all

Hided

10998 - Flipping Colors

Posted: Mon Apr 17, 2006 5:47 pm
by C
I write following code to solve problem 10998, but i got "TL", and when I only change the input and output code to java code, and choose submit with java, it is accepted.Isn't it strange? Can anyone perhaps tell me what may be the error under C??

Code: Select all

Because it is accepted, so i hide the code here 8)
 

Posted: Mon Apr 17, 2006 7:57 pm
by Emilio
I think you are saying problem 10998, not 10988, ok?
I think this maybe can be the reason for TLE :wink:

Else you can try this line to read the input

Code: Select all

while((scanf("%d %d %lf %lf",&h,&v,&dh,&dv)==4) 
          && ((h!=0)||(v!=0)||(dh!=0)||(dv!=0))) 

Posted: Tue Apr 18, 2006 7:41 am
by lonelyone
please change the type of h, v to double
then you would get it accepted

but I don't know why, maybe it is the problem of Judge System
maybe using integer cause that too accurate

Lonely

Posted: Tue Apr 18, 2006 12:44 pm
by shamim
My interpretation is it is due to the breaking condition of the while loop. Istead of comparing double value as DOUBLE_VAL != 0, use the format
fabs(DOUBLE_VAL) > 1e-9.

Thank u !

Posted: Tue Apr 18, 2006 10:37 pm
by C
I have tried your idea and also changed the type of h,v to double, and it is accepted . Really thank u! :wink:

Posted: Tue Apr 18, 2006 10:41 pm
by C
Emilio wrote:I think you are saying problem 10998, not 10988, ok?
I think this maybe can be the reason for TLE :wink:

Else you can try this line to read the input

Code: Select all

while((scanf("%d %d %lf %lf",&h,&v,&dh,&dv)==4) 
          && ((h!=0)||(v!=0)||(dh!=0)||(dv!=0))) 
It is 10998 and i have also changed the title and it isn't because of what u have advised :P :P But thank u.

please change the type of h, v to double
then you would get it accepted
I did so and followed another advice that instead of (dh!=0) should be (fabs(dh)>1e-9), and I finally got AC :D :D

Thanks all.

Once again

Posted: Tue Apr 18, 2006 10:51 pm
by C
And for the problem 10964, I write following code and got WA, still however change input and output to java and got AC, and this time there's no such breaking condition. Maybe someone can also have a try and tell me the error ?? Thanks !

Code: Select all

Hided

Posted: Tue Apr 18, 2006 11:10 pm
by mamun
I just copied and pasted your posted solution and got AC.
So what's the problem?

Posted: Wed Apr 19, 2006 1:28 am
by C
mamun wrote:I just copied and pasted your posted solution and got AC.
So what's the problem?
Yes, now I get AC, but yesterday I really got WA..

Posted: Wed Apr 19, 2006 12:21 pm
by shamim
C wrote:
mamun wrote:I just copied and pasted your posted solution and got AC.
So what's the problem?
Yes, now I get AC, but yesterday I really got WA..
Maybe, you were submitting using the wrong problem number. It also happened to me sometimes.

Posted: Wed Apr 19, 2006 1:17 pm
by little joey
Because both codes are (almost) accepted solutions to problems, would you be so kind, Mr. C., to remove them?

Posted: Wed Apr 19, 2006 7:32 pm
by C
little joey wrote:Because both codes are (almost) accepted solutions to problems, would you be so kind, Mr. C., to remove them?
Sure 8)

Posted: Sat Apr 22, 2006 4:06 pm
by Moha
I think all posters should remove their codes from board, and let the problem solvers to solve problems by their own.
I don't like other solutions when i didn't get a problem.

10998 - Flipping Colors

Posted: Tue Oct 20, 2009 5:20 am
by mcero
I need help with this problem. I got TL (time limit exceeded), I am sure it's because I can't detect in a right way the end of input. I am doing this in Java, so any help would be great!
I repeat, I am sure that the problem is the detection of the end of input...
Here it is my code:

Code: Select all

import java.util.*;
import java.io.*;

public class Main {
		public static void main(String[]args) throws IOException {
		Scanner stdIn = new Scanner(System.in);
		BufferedReader teclado = new BufferedReader(new InputStreamReader(System.in));
		int cont = 1;
		while (stdIn.hasNext()) {
			double largo = stdIn.nextDouble();
			double ancho = stdIn.nextDouble();
			double h = stdIn.nextDouble();
			double v = stdIn.nextDouble();
			
			
			double wx = ancho;//x de la esquina superior derecha
			double wy = largo;//y de la esquina superior derecha
			boolean color; //false = black;

			System.out.println("Case " + cont + ":");
			long n = stdIn.nextLong();
			double xInicial = 0;	//x de la esquina inferior izquierda
			double yInicial = 0;	//y de la esquina inferior izquierda
			wx = ancho;//x de la esquina/ superior derecha
			wy = largo;//y de la esquina superior derecha
			for (long i = 0; i < n; i++) {
				color = false;
				double x = stdIn.nextDouble();
				double y = stdIn.nextDouble();
				double largoN = largo;
				double anchoN = ancho;
				xInicial = 0;
				yInicial = 0;
				double xp = xInicial + h * largoN;
				double yp = yInicial + v * anchoN;
				while(true) {
					if ((x < xp && y > yp)
						|| (x > xp && y < yp)) {
						String imprimir = "";
						imprimir = color? "white" : "black";
						System.out.println(imprimir);
						break;
					}
					else if (x > xp && y > yp){						
						color = !color;
						xInicial = xp;
						yInicial = yp;
						largoN = wx - xp;
						anchoN = wy - yp;
						xp = xp + h * largoN;
						yp = yp + v * anchoN; 
					}
					else {
						color = !color;
						wx = xp;
						wy = yp;
						largoN = xp - xInicial;
						anchoN = yp - yInicial;
						xp = xInicial + h * largoN;
						yp = yInicial + v * anchoN;
					}
				}
			}	//for
			cont++;
		}	//while
	}	//main
	
}	//clase