Page 1 of 1

11130 - Billiard bounces

Posted: Thu Dec 02, 2010 12:13 pm
by mamohtei
Good day.

I got a "Wrong answer". But I have the right answers for the "Input", given in the problem.
Please give me other correct examples of the "Input\Output".

Thanks.

Re: 11130 - Billiard bounces

Posted: Mon Oct 24, 2011 9:47 am
by brianfry713
Input:
100 50 10 0 10
10 30 40 52 10000
30 42 100 23 10003
24 53 234 62 10340
0 0 0 0 0

Output from my AC program:
1 0
12313 5253
15346 4653
23665 20154

There is a bug in the problem description. The first input a is actually the length of the vertical side and the second input b is the length of the horizontal side.

Re: 11130 - Billiard bounces

Posted: Sun Apr 22, 2012 9:30 pm
by mamohtei
brianfry713 wrote:Input:
100 50 10 0 10
10 30 40 52 10000
30 42 100 23 10003
24 53 234 62 10340

Output from my AC program:
1 0
12313 5253
15346 4653
23665 20154

There is a bug in the problem description. The first input a is actually the length of the vertical side and the second input b is the length of the horizontal side.
I used your example. And I got the same result like yours. But I do not quite understand your last sentence.
Here is my java program list:

Code: Select all

// 11130 - Billiard bounces
import java.io.*;
import java.util.*;

class Main {
	static String ReadLn(int maxLg) // utility function to read from stdin
	{
		byte lin[] = new byte[maxLg];
		int lg = 0, car = -1;
		String line = "";

		try {
			while (lg < maxLg) {
				car = System.in.read();
				if ((car < 0) || (car == '\n'))
					break;
				lin[lg++] += car;
			}
		} catch (IOException e) {
			return (null);
		}

		if ((car < 0) && (lg == 0))
			return (null); // eof
		return (new String(lin, 0, lg));
	}

	public static void main(String args[]) // entry point from OS
	{
		Main myWork = new Main(); // create a dinamic instance
		myWork.Begin(); // the true entry point
	}

	void Begin() {
		String input;
		StringTokenizer idata;
		int a, b, v, s, verTouched, horTouched;
		double A, sinA, cosA, l, lTemp, lTempVer, lTempHor;

		while ((input = Main.ReadLn(255)) != null) {
			idata = new StringTokenizer(input);
			a = Integer.parseInt(idata.nextToken());
			b = Integer.parseInt(idata.nextToken());
			v = Integer.parseInt(idata.nextToken());
			A = Integer.parseInt(idata.nextToken());
			s = Integer.parseInt(idata.nextToken());

			if (a == 0 && b == 0 && v == 0 && A == 0 && s == 0)
				break;

			l = (v * s) / 2;
			verTouched = 0;
			horTouched = 0;
			lTemp = 0;

			if (A == 90) {
				lTemp = b / 2;
				while (lTemp <= l) {
					horTouched++;
					lTemp += b;

				}
			}

			if (A == 0) {
				lTemp = a / 2;
				while (lTemp <= l) {
					verTouched++;
					lTemp += a;

				}

			}

			if (A > 0 && A < 90) {
				A = (A * Math.PI) / 180;
				sinA = (double) Math.round(Math.sin(A) * 10000000) / 10000000;
				cosA = (double) Math.round(Math.cos(A) * 10000000) / 10000000;
				lTempVer = 0;
				lTempHor = 0;
				lTempHor = (b / 2) / sinA;
				lTempVer = (a / 2) / cosA;

				if (l >= lTempHor || l >= lTempVer) {

					while (lTemp <= l) {

						if (lTempHor < lTempVer) {
							lTemp += lTempHor;
							if (lTemp <= l)
								horTouched++;
							lTempVer = lTempVer - lTempHor;
							lTempHor = b / sinA;

						} else if (lTempHor > lTempVer) {
							lTemp += lTempVer;
							if (lTemp <= l)
								verTouched++;
							lTempHor = lTempHor - lTempVer;
							lTempVer = a / cosA;

						} else if (lTempHor == lTempVer) {
							lTemp += lTempVer;
							if (lTemp <= l) {
								horTouched++;
								verTouched++;
							}

							lTempHor = a / cosA;
							lTempVer = b / sinA;

						}

					}

				}
			}

			System.out.println(verTouched + " " + horTouched);
		}
	}
}

Re: 11130 - Billiard bounces

Posted: Mon Apr 23, 2012 11:44 pm
by brianfry713
Change these lines:
sinA = (double) Math.round(Math.sin(A) * 10000000) / 10000000;
cosA = (double) Math.round(Math.cos(A) * 10000000) / 10000000;
to:
sinA = Math.sin(A);
cosA = Math.cos(A);

Re: 11130 - Billiard bounces

Posted: Sun Sep 08, 2013 9:34 pm
by ak92thelooser
Edit : AC

Re: 11130 - Billiard bounces

Posted: Tue Sep 10, 2013 12:53 am
by brianfry713
Try using M_PI instead of your PI constant.

Re: 11130 - Billiard bounces

Posted: Sun Dec 08, 2013 11:37 pm
by Repon kumar Roy

Code: Select all

#include <stdio.h>
#include <math.h>
#define PI acos(-1)
int main(int argc, const char * argv[])
{

    long long hor,ver,speed,ang,time;
    double hor_ans,ver_ans,hor_component, ver_component;
    while (scanf("%lld %lld %lld %lld %lld",&hor,&ver,&speed,&ang,&time)==5) {
        if (hor+ver+speed+ang+time==0) {
            break;
        }
        hor_component = speed * cos(PI*ang/180.);
        ver_component = speed * sin(PI*ang /180.);
        
        hor_ans = hor_component * time/2;
        
        hor_component = hor_ans-hor/2;
        if (hor_component>=0) {
            hor_ans = 1+hor_component/hor + pow(10, -11);
        }
        else hor_ans=0;
        
        
        ver_ans = ver_component * time/2;
        ver_component = ver_ans-ver/2;
        if (ver_component>=0) {
            ver_ans = 1+ver_component/ver + pow(10, -11);
        }
        else ver_ans=0;
        
        hor = (long long) hor_ans;
        ver = (long long ) ver_ans;
        
        printf("%lld %lld\n",hor,ver);
    }
    return 0;
}


My input and output is matched with yours given. I just swaped the result ...
But I am getting WA.

Re: 11130 - Billiard bounces

Posted: Tue Dec 10, 2013 11:19 pm
by brianfry713
Input:

Code: Select all

88 33 7 48 19
77 74 60 7 71
38 33 89 5 11
39 25 6 35 28
38 54 91 77 20
89 94 29 74 87
48 51 7 51 45
47 53 71 86 94
99 87 96 39 47
91 90 51 38 33
63 32 13 16 41
15 82 10 20 2
29 5 79 71 99
55 97 2 15 26
82 95 69 85 48
69 18 47 42 68
41 53 78 52 89
36 2 11 73 41
56 55 62 21 25
81 44 58 34 90
0 0 0 0 0
AC output:

Code: Select all

1 1
27 4
13 1
2 2
5 16
4 13
2 2
5 63
18 16
7 6
4 2
1 0
44 739
0 0
2 17
17 59
52 52
2 108
13 5
27 33

Re: 11130 - Billiard bounces

Posted: Mon Jul 28, 2014 1:58 pm
by piyukr
Hi, my code runs fine on the inputs that you prepared, still I got WA.Can you please check my code --> http://ideone.com/kevO4T ?
Thanks.

Re: 11130 - Billiard bounces

Posted: Tue Jul 29, 2014 8:27 pm
by brianfry713
Try using double instead of float.

Re: 11130 - Billiard bounces

Posted: Fri Aug 01, 2014 7:03 am
by brianfry713
For input:
9593 7235 8682 30 9645
My AC output:
3780 2893

Re: 11130 - Billiard bounces

Posted: Fri Aug 01, 2014 7:26 am
by piyukr
here's my modified code http://ideone.com/2rmUXu, it gives the same output as yours, still WA.

Re: 11130 - Billiard bounces

Posted: Sat Aug 02, 2014 12:19 am
by brianfry713
Input:

Code: Select all

207 3999 6033 60 4830
0 0 0 0 0
AC output:

Code: Select all

35193 3155