Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- private static Rectangle vertical = new Rectangle();
- private static Rectangle horizontal = new Rectangle();
- public static void main(String[] args) {
- @SuppressWarnings("resource")
- Scanner scanner = new Scanner(System.in);
- double x = scanner.nextDouble();
- double y = scanner.nextDouble();
- double r = scanner.nextDouble();
- double rectVerticalX = x - r/2;
- double rectVerticalY = y + r;
- double rectVerticalWidth = r;
- double rectVerticalHeight = 2 * r;
- vertical.setX(rectVerticalX);
- vertical.setY(rectVerticalY);
- vertical.setWidth(rectVerticalWidth);
- vertical.setHeight(rectVerticalHeight);
- double rectHorizontalX = x - r;
- double rectHorizontalY = y + r/2;
- double rectHorizontalWidth = 2 * r;
- double rectHorizontalHeight = r;
- horizontal.setX(rectHorizontalX);
- horizontal.setY(rectHorizontalY);
- horizontal.setWidth(rectHorizontalWidth);
- horizontal.setHeight(rectHorizontalHeight);
- int n = scanner.nextInt();
- for (int i = 0; i < n; i++) {
- double pX = scanner.nextDouble();
- double pY = scanner.nextDouble();
- boolean isWithinTarget = vertical.contains(pX, pY) || horizontal.contains(pX, pY);
- if (isWithinTarget) {
- System.out.println("yes");
- } else {
- System.out.println("no");
- }
- }
- }
- }
- class Rectangle {
- private double x;
- private double y;
- private double width;
- private double height;
- public double getX() {
- return x;
- }
- public void setX(double x) {
- this.x = x;
- }
- public double getY() {
- return y;
- }
- public void setY(double y) {
- this.y = y;
- }
- public double getWidth() {
- return width;
- }
- public void setWidth(double width) {
- this.width = width;
- }
- public double getHeight() {
- return height;
- }
- public void setHeight(double height) {
- this.height = height;
- }
- public boolean contains(double x, double y) {
- boolean isInside = y <= this.y && y >= this.y - this.height && x >= this.x && x <= this.x + this.width;
- return isInside;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement