light1260Race Track【点到线段最短距离】


G - 
Race Track
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

Once there was a country named Ajobdesh. One of the architects designed a race track in a famous stadium in that country.

The stadium was like a polygon. The architect made another polygon inside that stadium and the space in between the two polygons was the track. Unlike other countries their cars were circular.

Now you are asked to find the radius of the largest car that can complete the track. Or you can say that the car can move freely around the track.

Input

Input starts with an integer T (≤ 20), denoting the number of test cases.

Each case starts with a line containing an integer n (3 ≤ n ≤ 100) denoting the number of vertices of the polygon that was made by the architect. Each of the next n lines contains two integers xi yi denoting the co-ordinates of that polygon.

The next line contains an integer m (3 ≤ m ≤ 100) denoting the number of vertices of the polygon that formed the stadium. Each of the next mlines contains two integers xi yi denoting the co-ordinates of that polygon.

All coordinates have absolute value no larger than 1000. The points of the polygons can be given in either clockwise or counterclockwise order and the two polygons do not intersect or touch themselves or each other. The outer polygon encloses the inner polygon.

Output

For each case, print the case number and the radius of the largest car that can complete the track. Errors less than 10-6 will be ignored.

Sample Input

1

3

0 0

1 0

1 1

5

3 -3

3 3

-4 2

-1 -1

-2 -2

Sample Output

Case 1: 0.7071067812

题意:在一个多边形内画一个多边形求能让一个圆在两个多边形之间自由穿行的最小半径
解题思路:想的是能自由穿行所以应该是两个多边形轮廓相距的最小距离;所以就想采取枚举内多变形定点到外多变形各边的最小距离算出这些距离中最小的即可。就在网上找了点到线段距离的最短距离的代码代进去AC看来思路应该是正确的。
附:点到线段最短距离参考博客:http://blog.csdn.net/yjukh/article/details/5213577
AC代码:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define eps 1e-8
using namespace std;
struct point{
	double x,y;
}A[110],B[110];
double MIN(double a,double b){
	return a<b?a:b;
}
double GetPointDistance(point p1, point p2) 
{
 return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double GetNearestDistance(point PA, point PB, point P3)
{

//----------ͼ2--------------------
 double a,b,c;
 a=GetPointDistance(PB,P3);
 if(a<=0.00001)
  return 0.0f;
 b=GetPointDistance(PA,P3);
 if(b<=0.00001)
  return 0.0f;
 c=GetPointDistance(PA,PB);
 if(c<=0.00001)
  return a;//Èç¹ûPAºÍPB×ø±êÏàͬ£¬ÔòÍ˳öº¯Êý£¬²¢·µ»Ø¾àÀë
//------------------------------
 
 if(a*a>=b*b+c*c)//--------ͼ3--------
  return b;      //Èç¹ûÊǶ۽Ƿµ»Øb
 if(b*b>=a*a+c*c)//--------ͼ4-------
  return a;      //Èç¹ûÊǶ۽Ƿµ»Øa
 
//ͼ1
 double l=(a+b+c)/2;     //Öܳ¤µÄÒ»°ë
 double s=sqrt(l*(l-a)*(l-b)*(l-c));  //º£Â×¹«Ê½ÇóÃæ»ý£¬Ò²¿ÉÒÔÓÃʸÁ¿Çó
 return 2*s/c;
}
 
int main()
{
	int t,k=1,n,m,i,j;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(i=0;i<n;++i){
			scanf("%lf%lf",&A[i].x,&A[i].y);
		}
		scanf("%d",&m);
		for(i=0;i<m;++i){
			scanf("%lf%lf",&B[i].x,&B[i].y);
		}
		double ans=1e20;
		for(i=0;i<n;++i){
			for(j=0;j<m;++j){
				ans=MIN(ans,GetNearestDistance(B[j],B[(j+1)%m],A[i]));
			}
		}
		printf("Case %d: %.7lf\n",k++,ans/2.0);
	}
	return 0;
}


 
      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值