Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.lang.reflect.Array;
- import java.util.*;
- import java.util.regex.*;
- import java.util.stream.Stream;
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int n = Integer.parseInt(scan.nextLine());
- HashMap<String, List<Integer>> Zones = new HashMap<>();
- for (int i = 0; i < n; i++) {
- String[] input = scan.nextLine().split(":");
- String name = input[0];
- String[] att = input[1].split(",");
- ArrayList<Integer> attributes = new ArrayList<>(5);
- for (int j = 0; j < att.length; j++) {
- att[j] = att[j].trim();
- attributes.add(Integer.parseInt(att[j]));
- }
- attributes.add(0);
- attributes.add(0);
- Zones.put(name, attributes);
- }
- String[] parkSpaces = scan.nextLine().split(";");
- String[] shopXY = scan.nextLine().split(",");
- int shopX = Integer.parseInt(shopXY[0]);
- int shopY = Integer.parseInt(shopXY[1]);
- int k = Integer.parseInt(scan.nextLine());
- for (String space : parkSpaces
- ) {
- int spaceX = Integer.parseInt(space.split(",")[0]);
- int spaceY = Integer.parseInt(space.split(",")[1]);
- for (int i = 0; i < Zones.size(); i++) {
- List<Integer> attributes = Zones.get((Zones.keySet().toArray())[i]);
- int zoneX = attributes.get(0);
- int zoneY = attributes.get(1);
- int w = attributes.get(2);
- int l = attributes.get(3);
- int bestX = attributes.get(5);
- int bestY = attributes.get(6);
- if (spaceX > zoneX && spaceX < zoneX + w
- && spaceY > zoneY && spaceY < zoneY + l) {
- bestDistance(attributes, bestX, bestY, shopX, shopY,
- spaceX, spaceY);
- }
- }
- }
- double bestPrice = Double.MAX_VALUE;
- double bestTime = Double.MAX_VALUE;
- String zoneName = null;
- int finalX = 0;
- int finalY = 0;
- for (int i = 0; i < Zones.size(); i++) {
- List<Integer> attributes = Zones.get((Zones.keySet().toArray())[i]);
- int bestX = attributes.get(5);
- int bestY = attributes.get(6);
- int price = attributes.get(4);
- int distance = checkDistance(bestX, bestY,shopX, shopY);
- int currentTime = k*2*distance;
- double temp = Math.ceil((double)currentTime/60);
- int currentPrice = (int)temp;
- currentPrice *= price;
- if (currentPrice<bestPrice || (currentPrice==bestPrice && currentTime<bestTime)){
- bestPrice = currentPrice;
- bestTime = currentTime;
- zoneName = Zones.keySet().toArray()[i].toString();
- finalX = bestX;
- finalY = bestY;
- }
- }
- System.out.println("Zone Type: " + zoneName + "; ");
- System.out.printf("X: %s; Y: %s; Price: %s", finalX, finalY, bestPrice);
- }
- private static void bestDistance (List < Integer > att,int bestX, int bestY, int shopX, int shopY, int spaceX,
- int spaceY){
- int currentDistance = checkDistance(spaceX, spaceY, shopX, shopY);
- int bestDistance = checkDistance(bestX, bestY, shopX, shopY);
- if (currentDistance > bestDistance) {
- att.set(5, spaceX);
- att.set(6, spaceY);
- }
- }
- private static int checkDistance ( int spaceX, int spaceY, int shopX, int shopY){
- int result = Math.abs(spaceX - shopX) + Math.abs(spaceY - shopY);
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement