Weapon

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 270    Accepted Submission(s): 212

Problem Description
Doctor D. are researching for a horrific weapon. The muzzle of the weapon is a circle. When it fires, rays form a cylinder that runs through the circle verticality in both side. If one cylinder of rays touch another, there will be an horrific explosion. Originally, all circles can rotate easily. But for some unknown reasons they can not rotate any more. If these weapon can also make an explosion, then Doctor D. is lucky that he can also test the power of the weapon. If not, he would try to make an explosion by other means. One way is to find a medium to connect two cylinder. But he need to know the minimum length of medium he will prepare. When the medium connect the surface of the two cylinder, it may make an explosion.
 
Input
The first line contains an integer T, indicating the number of testcases. For each testcase, the first line contains one integer N(1 < N < 30), the number of weapons. Each of the next 3N lines  contains three float numbers. Every 3 lines represent one weapon. The first line represents the coordinates of center of the circle, and the second line and the third line represent two points in the circle which surrounds the center. It is supposed that these three points are not in one straight line. All float numbers are between -1000000 to 1000000.
 
Output
For each testcase, if there are two cylinder can touch each other, then output 'Lucky', otherwise output then minimum distance of any two cylinders, rounded to two decimals, where distance of two cylinders is the minimum distance of any two point in the surface of two cylinders.
 
Sample Input
3
3
0 0 0
1 0 0
0 0 1
5 2 2
5 3 2
5 2 3
10 22 -2
11 22 -1
11 22 -3
3
0 0 0
1 0 1.5
1 0 -1.5
112 115 109
114 112 110
109 114 111
-110 -121 -130
-115 -129 -140
-104 -114 -119.801961
3
0 0 0
1 0 1.5
1 0 -1.5
112 115 109
114 112 110
109 114 111
-110 -121 -130
-120 -137 -150
-98 -107 -109.603922
 
Sample Output
Lucky
2.32
Lucky
 
Source
 

                   
 题目大意:当时LOR做出来了之后,我就看了一下,题目在二十分钟之内读懂了。但是想复杂了,没有直接转换思路。题目给你很多无限延伸的圆柱,问你有没有相交的,有的话输出Lucky没有的话输出还差的最小距离。

             解题思路:当时没有想到直接可以抽象成经过圆心垂直于圆面的直线的距离,再与两个半径之和相比。就好比求两个圆是否相交,只用求两个圆心之间的距离,然后与半径之和相比,是一样的思路。

             题目地址:Weapon

基础知识  
求两条异面直线的距离


当然求两条异面直线的距离,可以找到两条直线的公垂向量,然后在两条直线上面找两个点连成直线直接往上面射影即可。感谢程怀俊。当然这个题找点的话可以直接用开始给的圆心。

  1. 若向量a=(a1,b1,c1),向量b=(a2,b2,c2),
  2. 向量a·向量b=a1a2+b1b2+c1c2
  3. 向量a×向量b=(b1c2-b2c1,c1a2-a1c2,a1b2-a2b1)
  4. ijk分别为空间中相互垂直的三条坐标轴的单位向量)。

不过这个题目还debug了一下。因为两个向量
点乘的时候可能是负的,夹角大于90度的时候。所以需要转化为正。具体见代码。



AC代码:代码配合下面图片使用

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<cmath>
  5. using namespace std;
  6.  
  7. struct mq
  8. {
  9. double x; //x,y,z表示垂直于圆表面的向量
  10. double y;
  11. double z;
  12. double a; //a,b,c圆心的坐标
  13. double b;
  14. double c;
  15. double r; //r圆的半径
  16. };
  17. mq node[42];
  18.  
  19. double solve(mq p1,mq p2)
  20. {
  21. double a1,b1,c1,a2,b2,c2;
  22. double s1,s2,s3; //s向量
  23. double q1,q2,q3;
  24. double ans1,ans2,ans;
  25. a1=p1.x,b1=p1.y,c1=p1.z;
  26. a2=p2.x,b2=p2.y,c2=p2.z;
  27. s1=b1*c2-b2*c1,s2=c1*a2-c2*a1;
  28. s3=a1*b2-a2*b1;
  29. q1=p2.a-p1.a,q2=p2.b-p1.b;
  30. q3=p2.c-p1.c;
  31. ans1=fabs(q1*s1+q2*s2+q3*s3);
  32. ans2=sqrt(s1*s1+s2*s2+s3*s3);
  33. ans=ans1/ans2;
  34. return ans;
  35. }
  36.  
  37. int main()
  38. {
  39. int tes,n,i,j;
  40. double x1,y1,z1,x2,y2,z2,x3,y3,z3;
  41. double a1,b1,c1,a2,b2,c2;
  42. scanf("%d",&tes);
  43. while(tes--)
  44. {
  45. scanf("%d",&n);
  46. for(i=0;i<n;i++)
  47. {
  48. scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&z1,&x2,&y2,&z2,&x3,&y3,&z3);
  49. node[i].a=x1,node[i].b=y1,node[i].c=z1,
  50. a1=x2-x1,b1=y2-y1,c1=z2-z1;
  51. a2=x3-x1,b2=y3-y1,c2=z3-z1;
  52. node[i].r=sqrt(a1*a1+b1*b1+c1*c1); //半径
  53. node[i].x=b1*c2-b2*c1,node[i].y=c1*a2-c2*a1;
  54. node[i].z=a1*b2-a2*b1;
  55. }
  56.  
  57. int flag=0;
  58. double res=10000000;
  59. double tmp;
  60. //tmp=solve(node[0],node[1]);
  61. //printf("%.2f\n",tmp);
  62. for(i=0;i<n;i++)
  63. {
  64. for(j=i+1;j<n;j++)
  65. {
  66. tmp=solve(node[i],node[j]); //tmp返回的是两条中间的线的距离
  67. tmp=tmp-node[i].r-node[j].r;
  68. if(tmp<=0)
  69. {
  70. flag=1;
  71. break;
  72. }
  73. if(tmp<res)
  74. res=tmp;
  75. }
  76. if(flag)
  77. break;
  78. }
  79. if(flag) puts("Lucky");
  80. else printf("%.2f\n",res);
  81.  
  82. }
  83. return 0;
  84. }


HDU 4617Weapon(两条异面直线的距离)的更多相关文章

  1. C# 判断两条直线距离

    本文告诉大家获得两条一般式直线距离 一般式的意思就是 Ax+By+C=0" role="presentation">Ax+By+C=0Ax+By+C=0 如果有两个 ...

  2. 2018-7-31-C#-判断两条直线距离

    title author date CreateTime categories C# 判断两条直线距离 lindexi 2018-07-31 14:38:13 +0800 2018-05-08 10: ...

  3. hdu 4617 Weapon【异面直线距离——基础三维几何】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4617 Weapon Time Limit: 3000/1000 MS (Java/Others)     ...

  4. 求空间内两条直线的最近距离以及最近点的坐标(C++)

    关键词:空间几何 用途:总有地方会用到吧 文章类型:C++函数展示 @Author:VShawn(singlex@foxmail.com) @Date:2016-11-19 @Lab: CvLab20 ...

  5. 两条直线(蓝桥杯)二分枚举+RMQ

    算法提高 两条直线   时间限制:1.0s   内存限制:256.0MB        问题描述 给定平面上n个点. 求两条直线,这两条直线互相垂直,而且它们与x轴的夹角为45度,并且n个点中离这两条 ...

  6. 旋转卡壳求两个凸包最近距离poj3608

    #include <iostream> #include <cmath> #include <vector> #include <string.h> # ...

  7. 笔试算法题(19):判断两条单向链表的公共节点 & 字符集删除函数

    出题:给定两个单向链表的头结点,判断其是否有公共节点并确定第一个公共节点的索引: 分析: 由于是单向链表,所以每个节点有且仅有一个后续节点,所以只可能是Y型交叉(每条链表中的某个节点同时指向一个公共节 ...

  8. 在3D中两条射线的相交性检测

    摘自[3D数学基础: 图形与游戏开发] 考虑在3D中两条以参数形式定义的射线: \(\vec{r_1}(t_1)=\vec{p_1}+t_1\vec{d_1}\) \(\vec{r_2}(t_2)=\ ...

  9. 给定数轴上的n个点,求距离最近的两个点的距离

    public class MinimumSpacing { //给定平面上的n个点,求距离最近的两个点的距离. //无从下手的话,先分解问题,分解成简单的,逐个分析,然后再合在一起考虑 //这是个2维 ...

随机推荐

  1. PhoneGap 开发笔记

    1 调死调活都调不出来的情况下,可以考虑更换下phoneGap 版本,尽量用比较新的版本. 2 form submit 会返回 3 jquery mobile 的4个初始化事件 第一个触发的事件是mo ...

  2. BZOJ 1023

    program bzoj1023; uses math; ; maxn=; maxm=; type edge=record togo,next:longint; end; var n,m,cnt,in ...

  3. JAVA面试中的几个重要基础问题

    1.java是否会出现内存溢出?如何解决? 内存溢出是指应用系统中存在无法回收的内存或使用的内存过多,最终使得程序运行要用到的内存大于虚拟机能提供的最大内存.为了解决Java中内存溢出问题,我们首先必 ...

  4. oracle 中的select ...connect by prior ...start with 及(+)的用法

    1.select ...connect by prior ...start with的用法: select ... from <tablename> where <condition ...

  5. 开源html5_kiwijs_helloworld

    本次须要的下载文件已经共享出来 网盘地址 由于我使用的是黑苹果系统, window我就无视了. 开发工具使用 网盘里的 dmg :Sublime Text 打开开发工具后在helloworld中找到 ...

  6. HTML5.1就要来了

    原文来自https://www.w3.org/blog/2016/04/working-on-html5-1/ 总结一下几个点: 1.六个月内,也就是到九月份的时候,HTML5.1会和大家见面. 2. ...

  7. [译]Stairway to Integration Services Level 13 - SSIS 变量回顾

    介绍 在前一篇中我们组合了已经学过的事件冒泡 event bubbling, 日志记录 logging, 和父子模型 Parent-Child pattern 建立了自定义的SSIS包日志记录. 本文 ...

  8. C#之简单选择排序

    以排列INT数组为简单示范 namespace 简单选择排序 { class Program { static void SelectViod(int[] data) { ; i < data. ...

  9. spring的常用配置

    bean.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http ...

  10. 裸机离奇事件:Freescale usb 有关fault

    裸机离奇事件:Freescale usbucosiiFreescale\KSDK_1.2.0\examples\twrk65f180m\demo_apps\usb\host\cdc\cdc_seria ...