Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.lang.Integer;
- import java.lang.String;
- import java.util.*;
- public class Main {
- public static void main(String args[]) throws IOException {
- File file = new File("input.txt");
- ArrayList<Node> nodes = parseText(file);
- //System.out.println(Graph.addEdge(nodes));
- }
- public static ArrayList<Node> parseText(File file) throws IOException {
- ArrayList<Node> nodes = new ArrayList<>();
- BufferedReader br = new BufferedReader(new FileReader(file));
- String line;
- while ((line = br.readLine()) != null) {
- String[] words = line.split("\\s+");
- ArrayList<Integer> data = new ArrayList<Integer>();
- for(int i = 3; i < words.length; i++ )
- {
- data.add(Integer.parseInt(words[i]));
- // System.out.println(data);
- }
- Node n = new Node(Integer.parseInt(words[0]), Float.parseFloat(words[1]), Float.parseFloat(words[2]), data);
- nodes.add(n);
- System.out.println(n);
- }
- br.close();
- return nodes;
- }
- }
- class Node {
- public int id;
- public float x, y;
- public boolean isBlack;
- public ArrayList<Integer> data;
- public Node(int id, float x, float y, ArrayList<Integer> data) {
- this.id = id;
- this.x = x;
- this.y = y;
- this.data = data;
- this.isBlack = id % 2 == 0 ? true : false;
- }
- public String toString() {
- String s = "[id:" + this.id + ", x:" + this.x + ", y:" + this.y + ", data:" + this.data + "]";
- return s;
- }
- public int getID() {
- return this.id;
- }
- }
- class Graph {
- public ArrayList<Double> edges = new ArrayList<>();
- public Node n;
- public Graph(ArrayList<Node> nodes, ArrayList<Double> edges, Node n) {
- this.edges = edges;
- }
- public ArrayList<Double> addEdge(ArrayList<Node> nodes) {
- float distx = 0;
- float disty = 0;
- double distall = 0;
- for(int i=0; i< nodes.size(); ++i) {
- for (int j=i+1; j<nodes.size(); ++j) {
- distx = nodes.get(i).x + nodes.get(j).x;
- disty = nodes.get(i).y + nodes.get(j).y;
- distall = Math.sqrt(distx*distx + disty*disty);
- edges.add(distall);
- }
- } return edges;
- }
- public double MDistance(Node node1, Node node2) {
- float dx = node1.x - node2.x;
- float dy = node1.y - node2.y;
- double dsum = Math.sqrt(dx*dx + dy*dy );
- return dsum;
- }
- }
- class Edge {
- public ArrayList<Double> edges;
- public ArrayList<Node> nodes;
- public Edge(ArrayList<Double> edges, ArrayList<Node> nodes) {
- this.edges = edges;
- this.nodes = nodes;
- System.out.println(Graph.addEdge(nodes));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement