Java实现 洛谷 Car的旅行路线

Java实现 洛谷 Car的旅行路线_第1张图片

Java实现 洛谷 Car的旅行路线_第2张图片

输入输出样例
输入样例#1:
1
3 10 1 3
1 1 1 3 3 1 30
2 5 7 4 5 2 1
8 6 8 8 11 6 3
输出样例#1:
47.5

import java.util.Scanner;

//洛谷
public class car的旅行路线 {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int cout=in.nextInt();
		for (int ss = 0; ss dp[i][j]){
					min = dp[i][j];
					//System.out.println(i+" "+j+" "+min);
				}
			}
		}
		
		System.out.printf("%.1f", min);
	}
	}
	private static double dist(int x12, int y12, int x22, int y22) {
		// TODO Auto-generated method stub
		return Math.sqrt((x22-x12)*(x22-x12)+(y22-y12)*(y22-y12));
	}

}


class City{
	
	int []x = new int[4];
	int []y = new int[4];
	int price;
	public City(int x1, int y1, int x2, int y2, int x3, int y3,  int price) {
		super();
		x[0] = x1;
		y[0] = y1;
		x[1] = x2;
		y[1] = y2;
		x[2] = x3;
		y[2] = y3;
		
		double t12 = dist(x1,y1,x2,y2);
		double t13 = dist(x1,y1,x3,y3);
		double t23 = dist(x2,y2,x3,y3);
		
		if(Math.abs(t12*t12+t13*t13-t23*t23)<0.000001){
			x[3] = x2+x3-x1;
			y[3] = y2+y3-y1;
		}
		
		if(Math.abs(t12*t12+t23*t23-t13*t13)<0.000001){
			x[3] = x1+x3-x2;
			y[3] = y1+y3-y2;
		}
		
		if(Math.abs(t13*t13+t23*t23-t12*t12)<0.000001){
			x[3] = x1+x2-x3;
			y[3] = y1+y2-y3;
		}
		
		this.price = price;
	}
	private double dist(int x12, int y12, int x22, int y22) {
		// TODO Auto-generated method stub
		return Math.sqrt((x22-x12)*(x22-x12)+(y22-y12)*(y22-y12));
	}

}

你可能感兴趣的:(洛谷)