Advertisement
dimipan80

Exam 2. Durts

Sep 10th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _2_Durts {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner scan = new Scanner(System.in);
  8.         int centerX = scan.nextInt();
  9.         int centerY = scan.nextInt();
  10.         int size = scan.nextInt();
  11.         int count = scan.nextInt();
  12.  
  13.         int pointX, pointY;
  14.         for (int i = 0; i < count; i++) {
  15.             pointX = scan.nextInt();
  16.             pointY = scan.nextInt();
  17.  
  18.             int minLeft = centerX - size;
  19.             int maxRight = centerX + size;
  20.             int bottom = centerY - (size / 2);
  21.             int top = centerY + (size / 2);
  22.  
  23.             boolean pointIsInside = pointX >= minLeft && pointX <= maxRight
  24.                     && pointY >= bottom && pointY <= top;
  25.  
  26.             if (!pointIsInside) {
  27.                 minLeft = centerX - (size / 2);
  28.                 maxRight = centerX + (size / 2);
  29.                 bottom = centerY - size;
  30.                 top = centerY + size;
  31.  
  32.                 pointIsInside = pointX >= minLeft && pointX <= maxRight
  33.                         && pointY >= bottom && pointY <= top;
  34.             }
  35.  
  36.             System.out.println(pointIsInside ? "yes" : "no");
  37.         }
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement