Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- int n = Integer.parseInt(reader.readLine());
- List<Zone> allZones = new ArrayList<>();
- List<ParkingSpace> allParkingSpaces = new ArrayList<>();
- for (int i = 0; i < n; i++) {
- String[] input = reader.readLine().split(" ");
- String name = input[0].substring(0, input[0].length() - 1);
- int x = Integer.parseInt(input[1].substring(0, input[1].length() - 1));
- int y = Integer.parseInt(input[2].substring(0, input[2].length() - 1));
- int length = Integer.parseInt(input[3].substring(0, input[3].length() - 1));
- int width = Integer.parseInt(input[4].substring(0, input[4].length() - 1));
- double price = Double.parseDouble(input[5]);
- allZones.add(new Zone(name, x, y, length, width, price));
- }
- String[] input = reader.readLine().split("; ");
- String[] shopCoordinates = reader.readLine().split(", ");
- int timePerBlock = Integer.parseInt(reader.readLine());
- int shopX = Integer.parseInt(shopCoordinates[0]);
- int shopY = Integer.parseInt(shopCoordinates[1]);
- for (int i = 0; i < input.length; i++) {
- int currentParkingPointX = Integer.parseInt(input[i].split(", ")[0]);
- int currentParkingPointY = Integer.parseInt(input[i].split(", ")[1]);
- for (Zone zone : allZones) {
- if (zone.isParkingSpaceInThisZone(currentParkingPointX, currentParkingPointY)) {
- allParkingSpaces.add(new ParkingSpace(currentParkingPointX, currentParkingPointY,
- zone.getPricePerMin(), zone.getName(), shopX, shopY, timePerBlock));
- break;
- }
- }
- }
- ParkingSpace cheapestParking = allParkingSpaces.stream().min(Comparator.comparingDouble(ParkingSpace::getPriceToWait)).orElse(null);
- allParkingSpaces.removeIf(x -> x.getPriceToWait() > cheapestParking.getPriceToWait());
- ParkingSpace result = allParkingSpaces.stream().min(Comparator.comparingInt(ParkingSpace::getDistanceFromTheShop)).orElse(null);
- System.out.println(result.toString());
- }
- }
- class Zone {
- private String name;
- private int x;
- private int y;
- private int length;
- private int width;
- private double pricePerMin;
- public Zone(String name, int x, int y, int length, int width, double pricePerMin) {
- this.setX(x);
- this.setY(y);
- this.setLength(length);
- this.setWidth(width);
- this.setPricePerMin(pricePerMin);
- this.setName(name);
- }
- public boolean isParkingSpaceInThisZone(int x, int y) {
- boolean result = false;
- if ((this.getX() <= x && this.getWidth() + this.getX() - 1 >= x) && (this.getY() <= y && this.getLength() + this.getY() - 1 >= y)) {
- result = true;
- }
- return result;
- }
- public int getX() {
- return x;
- }
- private void setX(int x) {
- this.x = x;
- }
- public int getY() {
- return y;
- }
- private void setY(int y) {
- this.y = y;
- }
- public int getLength() {
- return length;
- }
- private void setLength(int length) {
- this.length = length;
- }
- public int getWidth() {
- return width;
- }
- private void setWidth(int width) {
- this.width = width;
- }
- public double getPricePerMin() {
- return pricePerMin;
- }
- private void setPricePerMin(double pricePerMin) {
- this.pricePerMin = pricePerMin;
- }
- public String getName() {
- return name;
- }
- private void setName(String name) {
- this.name = name;
- }
- }
- class ParkingSpace {
- private int x;
- private int y;
- private int distanceFromTheShop;
- private double priceToWait;
- private double pricePerMin;
- private String zoneName;
- public ParkingSpace(int x, int y, double pricePerMin, String zoneName, int shopX, int shopY, int timePerBlock) {
- this.setX(x);
- this.setY(y);
- this.setDistanceFromTheShop(shopX, shopY);
- this.setPriceToWait(timePerBlock);
- this.setPricePerMin(pricePerMin);
- this.setZoneName(zoneName);
- this.setPriceToWait(timePerBlock);
- }
- public int getX() {
- return x;
- }
- private void setX(int x) {
- this.x = x;
- }
- public int getY() {
- return y;
- }
- private void setY(int y) {
- this.y = y;
- }
- public int getDistanceFromTheShop() {
- return distanceFromTheShop;
- }
- private void setDistanceFromTheShop(int shopX, int shopY) {
- this.distanceFromTheShop = Math.abs(shopX - this.getX()) + Math.abs(shopY - this.getY()) - 1;
- }
- public double getPriceToWait() {
- return this.priceToWait;
- }
- private void setPriceToWait(int timePerBlock) {
- this.priceToWait = (Math.ceil((double)(this.getDistanceFromTheShop() * 2 * timePerBlock) / 60) * this.getPricePerMin());
- }
- public double getPricePerMin() {
- return pricePerMin;
- }
- private void setPricePerMin(double pricePerMin) {
- this.pricePerMin = pricePerMin;
- }
- public String getZoneName() {
- return zoneName;
- }
- private void setZoneName(String zoneName) {
- this.zoneName = zoneName;
- }
- @Override
- public String toString(){
- return String.format("Zone Type: %s; X: %s; Y: %s; Price: %.2f%n", this.getZoneName(), this.getX(), this.getY(), this.getPriceToWait());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement