11130 - Billiard bounces
Moderator: Board moderators
11130 - Billiard bounces
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.
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.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11130 - Billiard bounces
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.
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.
Last edited by brianfry713 on Tue Dec 10, 2013 11:14 pm, edited 1 time in total.
Check input and AC output for thousands of problems on uDebug!
Re: 11130 - Billiard bounces
I used your example. And I got the same result like yours. But I do not quite understand your last sentence.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.
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);
}
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11130 - Billiard bounces
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);
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);
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 1
- Joined: Sun Sep 08, 2013 9:20 pm
Re: 11130 - Billiard bounces
Edit : AC
Last edited by ak92thelooser on Sat Nov 08, 2014 3:48 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11130 - Billiard bounces
Try using M_PI instead of your PI constant.
Check input and AC output for thousands of problems on uDebug!
-
- Learning poster
- Posts: 96
- Joined: Tue Apr 23, 2013 12:54 pm
Re: 11130 - Billiard bounces
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;
}
But I am getting WA.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11130 - Billiard bounces
Input:AC output:
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
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
Check input and AC output for thousands of problems on uDebug!
Re: 11130 - Billiard bounces
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.
Thanks.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11130 - Billiard bounces
Try using double instead of float.
Check input and AC output for thousands of problems on uDebug!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11130 - Billiard bounces
For input:
9593 7235 8682 30 9645
My AC output:
3780 2893
9593 7235 8682 30 9645
My AC output:
3780 2893
Check input and AC output for thousands of problems on uDebug!
Re: 11130 - Billiard bounces
here's my modified code http://ideone.com/2rmUXu, it gives the same output as yours, still WA.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11130 - Billiard bounces
Input:AC output:
Code: Select all
207 3999 6033 60 4830
0 0 0 0 0
Code: Select all
35193 3155
Check input and AC output for thousands of problems on uDebug!