11130 - Billiard bounces

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

Moderator: Board moderators

11130 - Billiard bounces

Postby mamohtei » Thu Dec 02, 2010 12:13 pm

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.
mamohtei
New poster
 
Posts: 2
Joined: Thu Dec 02, 2010 12:01 pm

Re: 11130 - Billiard bounces

Postby brianfry713 » Mon Oct 24, 2011 9:47 am

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.
brianfry713
Guru
 
Posts: 1751
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11130 - Billiard bounces

Postby mamohtei » Sun Apr 22, 2012 9:30 pm

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);
      }
   }
}
mamohtei
New poster
 
Posts: 2
Joined: Thu Dec 02, 2010 12:01 pm

Re: 11130 - Billiard bounces

Postby brianfry713 » Mon Apr 23, 2012 11:44 pm

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);
brianfry713
Guru
 
Posts: 1751
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA


Return to Volume CXI

Who is online

Users browsing this forum: No registered users and 0 guests