输入输出样例

输入样例#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 <cout; ss++) { int s = in.nextInt();//s表示城市的个数
int t = in.nextInt();//t代表飞机的单价
int A = in.nextInt();
int B = in.nextInt();
City []cities = new City[s];
for(int i = 0; i < s; i++){
int x1 = in.nextInt();
int y1 = in.nextInt();
int x2 = in.nextInt();
int y2 = in.nextInt();
int x3 = in.nextInt();
int y3 = in.nextInt();
int price = in.nextInt();
City city = new City(x1, y1, x2, y2, x3, y3, price);
cities[i] = city;
} double [][]dp = new double[s*4][s*4]; for(int i = 0; i < s*4; i++){
for( int j = 0; j < s*4 ;j++){
if(i/4==j/4){
dp[i][j] = dist(cities[i/4].x[i%4],cities[i/4].y[i%4],cities[j/4].x[j%4],cities[j/4].y[j%4])*cities[i/4].price;
}else{
dp[i][j] = dist(cities[i/4].x[i%4],cities[i/4].y[i%4],cities[j/4].x[j%4],cities[j/4].y[j%4])*t;
} //System.out.println(i+" "+j+" "+dp[i][j]);
}
} for(int i = 0; i < 4*s;i++){
for(int j = 0; j < 4*s; j++){
for(int k = 0; k < 4*s; k++){
dp[j][k] = Math.min(dp[j][k], dp[j][i]+dp[i][k]);
//System.out.println(j+" "+k+" "+dp[j][k]);
}
}
} double min = dp[(A-1)*4][(B-1)*4];
//System.out.println(min);
for(int i = (A-1)*4; i <A*4; i++){
for(int j = (B-1)*4; j <B*4; j++){
if(min>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));
} }

Java实现 洛谷 Car的旅行路线的更多相关文章

  1. 洛谷 P4478 [BJWC2018]上学路线

    洛谷 P4478 [BJWC2018]上学路线 原题 神仙题orz,竟然没有1A....容斥+卢卡斯+crt?? 首先用容斥做,记\(f[i][0/1]\)表示到i号点经过了奇数/偶数个点的方案数,因 ...

  2. 【模板】矩阵快速幂 洛谷P2233 [HNOI2002]公交车路线

    P2233 [HNOI2002]公交车路线 题目背景 在长沙城新建的环城公路上一共有8个公交站,分别为A.B.C.D.E.F.G.H.公共汽车只能够在相邻的两个公交站之间运行,因此你从某一个公交站到另 ...

  3. Java实现 洛谷 P1738 洛谷的文件夹

    题目描述 kkksc03是个非凡的空想家!在短时间内他设想了大量网页,然后总是交给可怜的lzn去实现. 洛谷的网页端,有很多文件夹,文件夹还套着文件夹. 例如:/luogu/application/c ...

  4. Java实现洛谷 P1428 小鱼比可爱

    题目描述 人比人,气死人:鱼比鱼,难死鱼.小鱼最近参加了一个"比可爱"比赛,比的是每只鱼的可爱程度.参赛的鱼被从左到右排成一排,头都朝向左边,然后每只鱼会得到一个整数数值,表示这只 ...

  5. [NOIP2012] 提高组 洛谷P1081 开车旅行

    题目描述 小 A 和小 B 决定利用假期外出旅行,他们将想去的城市从 1 到 N 编号,且编号较小的 城市在编号较大的城市的西边,已知各个城市的海拔高度互不相同,记城市 i 的海拔高度为 Hi,城市 ...

  6. 洛谷P2502[HAOI2006]旅行

    题目: Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光.Z小镇附近共有N个景点(编号为1,2,3,-,N),这些景点被M条道路连接着,所有道路都是双向的,两个景点之间可能有多条道路.也许 ...

  7. 洛谷 P1081 开车旅行(70)

    P1081 开车旅行 题目描述 小AA 和小BB 决定利用假期外出旅行,他们将想去的城市从 11到 NN 编号,且编号较小的城市在编号较大的城市的西边,已知各个城市的海拔高度互不相同,记城市 ii的海 ...

  8. java实现洛谷P3376【模板】网络最大流

    题目描述 如题,给出一个网络图,以及其源点和汇点,求出其网络最大流. 输入格式 第一行包含四个正整数N.M.S.T,分别表示点的个数.有向边的个数.源点序号.汇点序号. 接下来M行每行包含三个正整数u ...

  9. 洛谷 P3313 [SDOI2014]旅行 解题报告

    P3313 [SDOI2014]旅行 题目描述 S国有N个城市,编号从1到N.城市间用N-1条双向道路连接,满足从一个城市出发可以到达其它所有城市.每个城市信仰不同的宗教,如飞天面条神教.隐形独角兽教 ...

随机推荐

  1. Ubuntu 18.04 新系统 允许root远程登录

    1. 查看ssh服务器是否安装并启动 #sudo ps -e | grep ssh 1. 安装ssh服务器 #sudo apt-get install openssh-server 2. 配置sshd ...

  2. 基于 abp vNext 和 .NET Core 开发博客项目 - 使用 abp cli 搭建项目

    首先,默认咱们已经有了.net core 3.1的开发环境,如果你没有,快去下载... https://dotnet.microsoft.com/download 由于项目是基于abp vNext开发 ...

  3. 如何使用 Shebang Line (Python 虚拟环境)

    本文记录,如何在 Python Script 中使用 Shebang 行. Shebang Line 是什么: 也被叫做 Hashbang Line,只要是一个由,井号和叹号#!开头,并构成的字符序列 ...

  4. python --分隔符split()

    描述: python split()是通过指定分隔符对字符串进行切片,且可以指定分隔n+1个字符串. 语法: str.split(str="",num=string.count(s ...

  5. SpringBatch异常To use the default BatchConfigurer the context must contain no more thanone DataSource

    SpringBoot整合SpringBatch项目,已将代码开源至github,访问地址:https://github.com/cmlbeliever/SpringBatch 欢迎star or fo ...

  6. angular foreach的使用

    var myAppModule = angular.module('myApp', []); var values = { name : 'misko', gender : 'male', " ...

  7. PAT 1009 Product of Polynomials (25分) 指数做数组下标,系数做值

    题目 This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: E ...

  8. 【雕爷学编程】Arduino动手做(51)---触摸按键模块

    37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器和模块,依照实践(动手试试)出真知的理念,以学习和交流为目的,这里准备 ...

  9. centOS 开启服务器后无法访问(大坑啊)

    在开启了nodejs后,发现虽然ssh访问到主机,但是公网不能访问. 一番调试发现程序是正常的,也确实在监听着端口.折腾良久无果,在Vultr上发帖求助.几分钟后Vultr团队的工程师Joshua B ...

  10. 面试最后HR都要问一句"有没有什么问题要问我"?

    HR最想听到的问题是: 1.询问职位发展方面的问题: (1)比如:这个职位的未来的发展空间如何,公司是如何对员工进行绩效考评的...等等这类问题,可以让HR觉得你是一个有长远目标和规划的人. 2.询问 ...