hdu4617 Weapon(立体几何题)

Weapon

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


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&#160; 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
 
没啥技巧吧,就是直接算
思路:对于每一个圆柱,算出它的中心轴方向向量同时保存圆心坐标,算出两个直线之间的距离d,如果距离大于两个圆柱的半径之和那就记录mind=d-rr[i]-rr[j],否则就输出Lucky。两直线平行时距离好算,不平行时有点麻烦,用向量的叉乘来计算。

#include<stdio.h>
#include<math.h>
double r[31][3],center[31][3],rr[31];

int main()
{
	double x1,x2,x3,y1,y2,y3,z1,z2,z3,r1,r2,r3,mind,temp,temp1;
	double a1,b1,c1,a2,b2,c2;
	int t,n,m,i,j,k,flag;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
			scanf("%lf%lf%lf",&x1,&y1,&z1);
			scanf("%lf%lf%lf",&x2,&y2,&z2);
			scanf("%lf%lf%lf",&x3,&y3,&z3);
			center[i][0]=x1;
			center[i][1]=y1;
			center[i][2]=z1;
			rr[i]=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
			a1=x2-x1;
			b1=y2-y1;
			c1=z2-z1;
			a2=x3-x1;
			b2=y3-y1;
			c2=z3-z1;
			r1=b1*c2-b2*c1;
			r2=a2*c1-a1*c2;
			r3=a1*b2-a2*b1;
			r[i][0]=r1;
			r[i][1]=r2;
			r[i][2]=r3;
			//printf("%.4f %.4f %.4f %.4f\n",rr[i],r1,r2,r3);
		}
		mind=1000000000;
		flag=1;
		for(i=0;i<n-1&&flag;i++)
		{
			for(j=i+1;j<n;j++)
			{
				a1=r[i][0];
				b1=r[i][1];
				c1=r[i][2];
				a2=r[j][0];
				b2=r[j][1];
				c2=r[j][2];
				r1=b1*c2-b2*c1;//垂直
				r2=a2*c1-a1*c2;
				r3=a1*b2-a2*b1;
			//printf("%d %d %.4f %.4f %.4f\n",i,j,r1,r2,r3);
				if(!(r1==0&&r2==0&&r3==0))//两直线不平行
				{
					temp=fabs(((center[i][0]-center[j][0])*r1+(center[i][1]-center[j][1])*r2+(center[i][2]-center[j][2])*r3)/sqrt(r1*r1+r2*r2+r3*r3));//利用
					if(temp<=rr[i]+rr[j])
					{
						printf("Lucky\n");
						flag=0;
						break;
					}
					else if(mind>temp-(rr[i]+rr[j]))
						mind=temp-rr[i]-rr[j];
					//printf("%.2f\n",temp);
				}
				else //平行
				{
					a2=center[i][0]-center[j][0],b2=center[i][1]-center[j][1],c2=center[i][2]-center[j][2];
					temp1=sqrt(((b1*c2-b2*c1)*(b1*c2-b2*c1)+(a2*c1-a1*c2)*(a2*c1-a1*c2)+(a1*b2-b1*a2)*(a1*b2-b1*a2))/(a1*a1+b1*b1+c1*c1));
					if(temp1<=rr[i]+rr[j])
					{
						printf("Lucky\n");
						flag=0;
						break;
					}
					else if(mind>temp1-rr[i]-rr[j])
						mind=temp1-rr[i]-rr[j];
				}
			}
		}
		if(flag)
			printf("%.2f\n",mind);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值