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.
Moderator: Board moderators
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.
// 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);
}
}
}
Users browsing this forum: No registered users and 1 guest