NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import java.awt.*;
import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
* Created by narya on 4/29/17.
*/
public class Application {

public static void main(String[] args) throws IOException {

Scanner fileScan = new Scanner(new FileReader(new File("input2.txt"))); // Scanner to read from file
int numOfTables=0;
int numOfStaff=0;
int numOfKitchens=0;


numOfKitchens = fileScan.nextInt();
numOfTables = fileScan.nextInt();
numOfStaff = fileScan.nextInt();
ArrayList<Kitchen> kitchens = new ArrayList<Kitchen>();
ArrayList<Staff> staffs = new ArrayList<Staff>();
ArrayList<DinnerTable> tables = new ArrayList<DinnerTable>();
String[] strOutput = new String[numOfStaff];
for(int i = 0 ; i<numOfKitchens; i++){
Kitchen kitchen = new Kitchen(i,fileScan.nextInt(),fileScan.nextInt());
kitchens.add(kitchen);
}

for(int i = 0 ; i<numOfTables; i++){
DinnerTable dinnerTable = new DinnerTable(i,fileScan.nextInt(),fileScan.nextInt(),fileScan.nextInt());
tables.add(dinnerTable);
}

for(int i = 0 ; i<numOfStaff; i++){
Staff staff = new Staff(i,fileScan.nextInt());
staffs.add(staff);
}


Collections.sort(staffs);

// for(int i = 0 ; i<numOfStaff ; i++){
// System.out.println(staffs.get(i).dist);
// }
int count = 0 ;
boolean outLoop = true;

while (outLoop){
boolean innerLoop = true;
Point index = calcDist(kitchens,tables);
// 1. index kitchen 2.index table
Kitchen kt = kitchens.get(index.x);
DinnerTable dt = tables.get(index.y);
if(staffs.size()==0) break;
if(staffs.get(0).dist >= Point.distance(kt.posX,kt.posY,dt.posX,dt.posY)){
strOutput[staffs.get(0).staffID] = kt.kitchenID + " ";
staffs.get(0).dist -= Point.distance(kt.posX,kt.posY,dt.posX,dt.posY);
tables.remove(index.y);
int indexTable = calcDist(tables,dt);
DinnerTable nt = tables.get(indexTable);

while(innerLoop){
count++;
System.out.println(count);
if(staffs.get(0).dist >= Point.distance(nt.posX,nt.posY,dt.posX,dt.posY)){
strOutput[staffs.get(0).staffID] += nt.dinnerTableID + " ";
staffs.get(0).dist -= Point.distance(nt.posX,nt.posY,dt.posX,dt.posY);
tables.remove(indexTable);
indexTable = calcDist(tables,dt);
nt = tables.get(indexTable);
}
else{
staffs.remove(0);
innerLoop=false;
}
}


}
else{
strOutput[staffs.get(0).staffID] = "-1";
staffs.remove(0);
if(staffs.size()==0) outLoop=false;
}

}

FileWriter fileWriter = new FileWriter(new File("output2.txt")); // Scanner to read from file

for(int i = 0 ; i < numOfStaff ; i++){
fileWriter.write(strOutput[i]+"n");
//System.out.println(strOutput[i]);
}

fileWriter.close();


}


public static Point calcDist(ArrayList<Kitchen> kitchens, ArrayList<DinnerTable> dinnerTables){

int minKitchenIndex=0;
int minTableIndex=0;

double minDist = Integer.MAX_VALUE;
for(int i = 0 ; i<kitchens.size();i++){
Point kitchen = new Point(kitchens.get(i).posX, kitchens.get(i).posY);
for(int j = 0 ; j <dinnerTables.size(); j++){
Point table = new Point(dinnerTables.get(i).posX, dinnerTables.get(i).posY);
if(minDist> table.distance(kitchen) ){
minDist=table.distance(kitchen);
minKitchenIndex=i;
minTableIndex=j;
}
}
}

return new Point(minKitchenIndex,minTableIndex);

}

public static int calcDist(ArrayList<DinnerTable> dinnerTables, DinnerTable dinnerTable){
Point table = new Point(dinnerTable.posX,dinnerTable.posY);
int minTableIndex=0;
double minDist = Integer.MAX_VALUE;
for(int i = 0 ; i<dinnerTables.size();i++){
Point table1 = new Point(dinnerTables.get(i).posX, dinnerTables.get(i).posY);
if(minDist> table.distance(table1) && table.distance(table1)!=0){
minDist=table.distance(table1);
minTableIndex=i;
}
}
return minTableIndex;
}

/**
* Created by narya on 4/29/17.
*/
static class Staff implements Comparable {

int staffID;
int dist ;


public Staff(int staffID, int dist){
this.staffID=staffID;
this.dist=dist;
}


public int compareTo(Object comparestu) {
int compareage=((Staff)comparestu).dist;
/* For Ascending order*/
return this.dist-compareage;
}
}

/**
* Created by narya on 4/29/17.
*/
static class Kitchen {
int kitchenID;
int posX;
int posY;


public Kitchen(int kitchenID, int x, int y ){
this.kitchenID= kitchenID;
this.posX=x;
this.posY=y;

}
}

/**
* Created by narya on 4/29/17.
*/
static class DinnerTable {
int dinnerTableID;
int posX;
int posY;
int numOfCustomers;

DinnerTable(int ID, int x, int y , int z){
this.dinnerTableID=ID;
this.posX=x;
this.posY=y;
this.numOfCustomers=z;
}
}
}

/**
* Created by narya on 4/29/17.
*/




     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.