Advertisement
svetlozar_kirkov

Durts

Jan 25th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class Problem13_Durts {
  6.    
  7.     public static class Point{  // creates object "point" which can be stored easily in arraylist
  8.         private int x;          // has two attributes "x" and "y"
  9.         private int y;
  10.        
  11.         public Point(int x, int y){
  12.             this.x=x;
  13.             this.y=y;
  14.         }
  15.         public int getX(){
  16.             return x;
  17.         }
  18.         public int getY(){
  19.             return y;
  20.         }
  21.     }
  22.    
  23.     public static class Rectangle{      // creates object "rectangle" which is used to store the two crossed rectangles in the figure
  24.         private int Ax, Ay, Bx, By, Cx, Cy, Dx, Dy;     // rectangle's sides
  25.        
  26.         public Rectangle(int Ax, int Ay, int Bx, int By, int Cx, int Cy, int Dx, int Dy){
  27.             this.Ax=Ax;
  28.             this.Ay=Ay;
  29.             this.Bx=Bx;
  30.             this.By=By;
  31.             this.Cx=Cx;
  32.             this.Cy=Cy;
  33.             this.Dx=Dx;
  34.             this.Dy=Dy;
  35.         }
  36.     }
  37.  
  38.     public static void main(String[] args) {
  39.         Scanner input = new Scanner(System.in);
  40.         int centerX = input.nextInt();  // reading the first input lines
  41.         int centerY = input.nextInt();
  42.         int radius = input.nextInt();
  43.         int count = input.nextInt();
  44.         ArrayList<Point> darts = new ArrayList<Point>(); // arraylist for the points
  45.         for (int i = 0; i < count; i++){    // getting points until we reach the "count"
  46.             Point temp = new Point(input.nextInt(),input.nextInt()); //creating temp point
  47.             darts.add(temp);    // adding it to the list
  48.             }
  49.         // rectangle creation below
  50.         Rectangle horizontal = new Rectangle(centerX-radius,centerY+(radius/2),centerX+radius,
  51.                 centerY+(radius/2),centerX+radius,centerY+(radius/2)-radius,centerX-radius,centerY+(radius/2)-radius);
  52.         Rectangle vertical = new Rectangle(centerX-(radius/2),centerY+radius, centerX+(radius/2),centerY+radius,
  53.                 centerX+(radius/2),centerY-radius,centerX-(radius/2),centerY-radius);
  54.        
  55.        
  56.         for (int i = 0; i < darts.size(); i++){     // iterating through every point in the list
  57.             int currentX = darts.get(i).getX();     //and checking if it is inside any of the created rectangles
  58.             int currentY = darts.get(i).getY();
  59.             if ( (currentX >= horizontal.Ax && currentX <= horizontal.Cx && currentY >= horizontal.Dy &&
  60.                     currentY <= horizontal.Ay) || currentX >= vertical.Ax && currentX <= vertical.Cx &&
  61.                     currentY >= vertical.Dy && currentY <= vertical.Ay){
  62.                 System.out.println("yes");  // print yes if true
  63.             }
  64.             else {
  65.                 System.out.println("no"); // the point is outside the rectangles
  66.             }
  67.         }
  68.         input.close(); // very important :D
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement