10998 - Flipping Colors

All about problems in Volume 109. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

C
New poster
Posts: 35
Joined: Mon Apr 17, 2006 1:04 pm

C compiler

Post by C » Mon Apr 17, 2006 1:11 pm

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
Last edited by C on Wed Apr 19, 2006 7:32 pm, edited 2 times in total.

C
New poster
Posts: 35
Joined: Mon Apr 17, 2006 1:04 pm

10998 - Flipping Colors

Post by C » Mon Apr 17, 2006 5:47 pm

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)
 
Last edited by C on Thu Apr 20, 2006 9:23 am, edited 2 times in total.

Emilio
Experienced poster
Posts: 163
Joined: Sun Oct 17, 2004 8:31 pm
Location: Murcia, Spain

Post by Emilio » Mon Apr 17, 2006 7:57 pm

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))) 

lonelyone
Learning poster
Posts: 65
Joined: Sat Feb 19, 2005 6:53 pm

Post by lonelyone » Tue Apr 18, 2006 7:41 am

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

User avatar
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim » Tue Apr 18, 2006 12:44 pm

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.

C
New poster
Posts: 35
Joined: Mon Apr 17, 2006 1:04 pm

Thank u !

Post by C » Tue Apr 18, 2006 10:37 pm

I have tried your idea and also changed the type of h,v to double, and it is accepted . Really thank u! :wink:

C
New poster
Posts: 35
Joined: Mon Apr 17, 2006 1:04 pm

Post by C » Tue Apr 18, 2006 10:41 pm

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.

C
New poster
Posts: 35
Joined: Mon Apr 17, 2006 1:04 pm

Once again

Post by C » Tue Apr 18, 2006 10:51 pm

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
Last edited by C on Wed Apr 19, 2006 7:32 pm, edited 2 times in total.

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Tue Apr 18, 2006 11:10 pm

I just copied and pasted your posted solution and got AC.
So what's the problem?

C
New poster
Posts: 35
Joined: Mon Apr 17, 2006 1:04 pm

Post by C » Wed Apr 19, 2006 1:28 am

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..

User avatar
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim » Wed Apr 19, 2006 12:21 pm

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.

User avatar
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey » Wed Apr 19, 2006 1:17 pm

Because both codes are (almost) accepted solutions to problems, would you be so kind, Mr. C., to remove them?

C
New poster
Posts: 35
Joined: Mon Apr 17, 2006 1:04 pm

Post by C » Wed Apr 19, 2006 7:32 pm

little joey wrote:Because both codes are (almost) accepted solutions to problems, would you be so kind, Mr. C., to remove them?
Sure 8)

Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post by Moha » Sat Apr 22, 2006 4:06 pm

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.

mcero
New poster
Posts: 1
Joined: Tue Oct 20, 2009 5:11 am

10998 - Flipping Colors

Post by mcero » Tue Oct 20, 2009 5:20 am

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

Post Reply

Return to “Volume 109 (10900-10999)”