题目意思  就是说 有一个起点一个终点  和一些虫洞,从一个虫洞进去然后出来,是不需要消耗时间的,注意点就是,虫洞是一条线段,你可以从线段的任意位置进去,从任意位置出来; 所以从一个虫洞到另一个虫洞的距离变成了空间的直线距离;

线段到线段的最短距离  用三分的方法

                        #include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<cmath>
#define eps 1e-10
#define inf 0x1f1f1f1f
using namespace std; int dcmp( double a ){ if( abs(a) < eps ) return ; if(a > ) return ;return -;}
struct point{
double x,y,z;
point(){}
point( double x,double y,double z ):x(x),y(y),z(z){}
};
typedef point Vector ;
point operator + ( point a,point b ){
return point( a.x+b.x , a.y+b.y , a.z+b.z );
}
point operator - ( point a,point b ){
return point( a.x-b.x , a.y-b.y, a.z-b.z );
}
point operator * ( point a,double p ){
return point( a.x*p , a.y*p , a.z*p );
}
point operator / ( point a,double p ){
return point( a.x/p , a.y/p , a.z/p );
}
bool operator == ( point a,point b ){
if( dcmp(a.x-b.x) == && dcmp(a.y-b.y) == && dcmp(a.z-b.z) == )return ;
return ;
}
double Dot( point a,point b ){ return a.x*b.x + a.y*b.y + a.z*b.z; }
double Length( point a ){ return sqrt(Dot(a,a));}
double Angle( point a,point b ){ return acos(Dot(a,b))/Length(a)/Length(b); }
// 点到 平面p0 - n 的距离;n 必须为单位向量 n 是平面法向量
double p_po_n( const point &p,const point &po,const point n ){
return abs(Dot( p-po,n ));
}
// 点在 平面p0 - n 的投影 ; n 必须为单位向量 n 是平面法向量
point p_po_n_jec( const point &p,const point &p0,const point &n ){
return p-n*Dot( p-p0,n );
}
// 直线p1 p2 在平面 p0 - n 的交点,假设交点存在;唯一
point p_p_p( point p1,point p2,point p0,point n ){
point v = p2 - p1;
double t = ( Dot(n,p0-p1)/Dot(n,p2-p1) );
return p1 + v*t;
}
point cross( point a,point b ){
return point( a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z,a.x*b.y - a.y*b.x );
}
double area( point a,point b,point c ){ return Length(cross(b-a,c-a)); }
double dis_to_line( point p, point a,point b ){
point v1 = b-a, v2 = p-a;
return Length( cross(v1,v2)/Length(v1) );
}
// p 到 ab 线段的距离
double dis_to_segm( point p,point a,point b ){
if( a == b )return Length(p-a);
point v1 = b-a, v2 = p-a, v3 = p-b;
if( dcmp( Dot(v1,v2) ) < ) return Length(v2);
else if( dcmp( Dot(v1,v3) ) > ) return Length(v3);
else return Length(cross(v1,v2))/Length(v1);
}
// 四面体的体积
double volume( point a,point b,point c,point d ){
return Dot( d-a,cross(b-a,c-a) );
}
// 线段到线段的距离
double dis_l_to_l( point a,point b,point lt,point rt )
{
while( abs(rt.x - lt.x) > eps || abs(rt.y - lt.y) > eps || abs( rt.z - lt.z) > eps )
{
point temp; temp = lt + ( rt - lt )/3.0;
point now; now = lt + ( rt - lt )/3.0*2.0;
if( dis_to_segm(temp,a,b) < dis_to_segm(now,a,b) )
rt = now;
else lt = temp;
}
return dis_to_segm( rt,a,b );
}
point A[],B[];
double map[][];
double dis[]; int que[];bool vis[];
void spfa( int N )
{
int tail,hed; tail = hed = ;
for( int i = ; i < ; i++ )dis[i] = (<<);
memset( vis,,sizeof(vis) );
dis[] = ; que[tail++] = ; vis[] = true;
while( tail > hed )
{
int temp = que[hed++]; vis[temp] = false;
for( int i = ; i <= N; i++ )
if( dis[temp] + map[temp][i] < dis[i] )
{
dis[i] = dis[temp] + map[temp][i];
if( !vis[i] )
{
que[tail++] = i;
vis[i] = true;
}
}
}
}
int main( )
{
int T,N; scanf("%d",&T);
while( T-- )
{
scanf("%d",&N);
scanf("%lf%lf%lf",&A[].x,&A[].y,&A[].z);
scanf("%lf%lf%lf",&A[N+].x,&A[N+].y,&A[N+].z);
for( int i = ; i <= N; i++ )
{
scanf("%lf%lf%lf",&A[i].x,&A[i].y,&A[i].z);
scanf("%lf%lf%lf",&B[i].x,&B[i].y,&B[i].z);
}
for( int i = ; i <= N+; i++ )
for( int j = ; j <= N+; j++ )
map[i][j] = (<<);
map[][N+] = map[N+][] = Length( A[]-A[N+] );
for( int i = ; i <= N; i++ ){
map[i][] = map[][i] = dis_to_segm( A[],A[i],B[i] );
map[i][N+] = map[N+][i] = dis_to_segm( A[N+],A[i],B[i] );
}
for( int i = ; i <= N; i++ )
for( int j = i+; j <= N; j++ ){
map[i][j] = dis_l_to_l( A[i],B[i],A[j],B[j] );
map[j][i] = map[i][j];
}
spfa( N + );
printf("%.15lf\n",dis[N+]);
}
return ;
}

UESTC 1854的更多相关文章

  1. ACM:UESTC - 649 括号配对问题 - stack

      UESTC - 649  括号配对问题 Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu ...

  2. UESTC 1015 Lweb and pepper --前,后缀最值

    题意: n种食物,每种含花椒的概率为Pi,现在已经选择了[L,R]这个区间(下标)的食物,要再选一个,使总的食物只有一种含花椒的概率最大,问选哪个最好,相同的选下标小的. 解法: 就不写解法了.此处有 ...

  3. UESTC 1852 Traveling Cellsperson

    找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...

  4. UESTC 1851 Kings on a Chessboard

    状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged ...

  5. UESTC 30 最短路,floyd,水

    最短路 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Statu ...

  6. 【BZOJ】1854: [Scoi2010]游戏

    http://www.lydsy.com/JudgeOnline/problem.php?id=1854 题意:n个数据,每个数据有两个属性,要求取一些数据且每个数据取一个属性使得组成连续的一段单调递 ...

  7. uestc oj 1218 Pick The Sticks (01背包变形)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1218 给出n根木棒的长度和价值,最多可以装在一个长 l 的容器中,相邻木棒之间不允许重叠,且两边上的木棒,可 ...

  8. uestc oj 1217 The Battle of Chibi (dp + 离散化 + 树状数组)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 给你一个长为n的数组,问你有多少个长度严格为m的上升子序列. dp[i][j]表示以a[i]结尾长为j ...

  9. BZOJ 1854: [Scoi2010]游戏 无向图判环

    题目链接: 题目 1854: [Scoi2010]游戏 Time Limit: 5 Sec Memory Limit: 162 MB 问题描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装 ...

随机推荐

  1. poj 3621(最优比率环)

    题目链接:http://poj.org/problem?id=3621 思路:之前做过最小比率生成树,也是属于0/1整数划分问题,这次碰到这道最优比率环,很是熟悉,可惜精度没控制好,要不就是wa,要不 ...

  2. Struts2 Convention插件的使用(1)

    刚刚查阅官方文档(convention-plugin.html)并学习了Struts2的Convention插件,文章这里只作为一个笔记,建议大家去看官方文档比较清晰和全面. 需要在项目添加这些包 c ...

  3. chmod u+x ./j2sdk-1_4_2_04-linux-i586.bin的含义

    这句话是改变当前目录下的j2sdk-1_4_2_04-linux-i586.bin文件的权限. 具体地说: chmod命令用于改变文件权限. u 这里指文件所有者 +x 添加可执行权限 ./ 指当前目 ...

  4. lintcode:恢复IP地址

    恢复IP地址 给一个由数字组成的字符串.求出其可能恢复为的所有IP地址. 样例 给出字符串 "25525511135",所有可能的IP地址为: [ "255.255.11 ...

  5. cache写策略

    cache写策略 Write Through (完全写入) CPU向cache写入数据时,同时向memory也写一份,使cache和memory的数据保持一致.优点是简单,缺点是每次都要访问memor ...

  6. 计算视频播放的时间(pts)

    http://yejun8500.blog.163.com/blog/static/463360020095298410979/ 在解码视频流的时候对每一个视频帧都会有一个时间戳pts(显示时间戳), ...

  7. Keil 4.7a版本问题&Jlink Clone问题

    听PP说Keil 4.7A新出,支持代码自动补全.激动之至,keil官网急填,下载安装.  问题即刻遇见①,电脑蓝屏,安装包损坏.当下载安装包未下载完时,续传安装包没用了.还是重下载吧,免得浪费时间. ...

  8. Android百度地图开发05之公交信息检索 + 路线规划

    在上一篇blog中介绍过POI检索的使用,本篇blog主要介绍公交信息检索和线路规划的内容. 公交信息检索 实际上,公交信息检索与POI检索.在线建议检索非常相似,也是把你需要检索的信息发送给百度地图 ...

  9. Hadoop HDFS文件常用操作及注意事项

    Hadoop HDFS文件常用操作及注意事项 1.Copy a file from the local file system to HDFS The srcFile variable needs t ...

  10. 微信jssdk uploadImage 巨坑

    //解决IOS无法上传的坑 if (localId.indexOf("wxlocalresource") != -1) { localId = localId.replace(&q ...