ECUST 09年 校赛个人训练赛第五场总结
A Coming Near
#include<iostream>
#include<cmath>
using namespace std;
struct vertex
{
long x,y;
};
vertex prisonA[1000],prisonB[1000];
double disBetweenAB(int posA,int posB)
{
double tmp1 = prisonA[posA].x - prisonB[posB].x;
double tmp2 = prisonA[posA].y - prisonB[posB].y;
return sqrt(tmp1 * tmp1 + tmp2 * tmp2);
}
double disBetweenPointAndLine(long x0,long y0,long x1,long y1,long x2,long y2)
{
double a = y1-y2;
double b = x2-x1;
double c = x1*y2-x2*y1;
double d = (a*x0+b*y0+c)/sqrt(a*a+b*b);
double xp = (b*b*x0-a*b*y0-a*c)/(a*a+b*b);
double yp = (-a*b*x0+a*a*y0-b*c)/(a*a+b*b);
double xb = (x1>x2)?x1:x2;
double yb = (y1>y2)?y1:y2;
double xs = x1+x2-xb;
double ys = y1+y2-yb;
if(xp > xb || xp < xs || yp > yb || yp < ys)
return 50000000;
else
return fabs(d);
}
int main()
{
int m,n;
while(scanf("%d %d",&n,&m),n || m)
{
int i,j;
for(i = 0 ; i < n ; i ++)
scanf("%ld %ld",&prisonA[i].x,&prisonA[i].y);
for(i = 0 ; i < m ; i ++)
scanf("%ld %ld",&prisonB[i].x,&prisonB[i].y);
double tmpDouble = disBetweenAB(0,0);
for(i = 0 ; i < n ; i ++)
for(j = 0 ; j < m ; j ++)
if(disBetweenAB(i,j) < tmpDouble)
tmpDouble = disBetweenAB(i,j);
for(i = 0 ; i < n ; i ++)
for(j = 0 ; j < m ; j ++)
{
double tmpDouble2 = disBetweenPointAndLine(prisonA[i].x,prisonA[i].y
,prisonB[j].x,prisonB[j].y,prisonB[(j+1)%m].x,prisonB[(j+1)%m].y);
if(tmpDouble2 < tmpDouble)
tmpDouble = tmpDouble2;
};
for(i = 0 ; i < m ; i ++)
for(j = 0 ; j < n ; j ++)
{
double tmpDouble2 = disBetweenPointAndLine(prisonB[i].x,prisonB[i].y
,prisonA[j].x,prisonA[j].y,prisonA[(j+1)%n].x,prisonA[(j+1)%n].y);
if(tmpDouble2 < tmpDouble)
tmpDouble = tmpDouble2;
};
printf("%.2lf\n",tmpDouble);
}
return 0;
}B Love Letter
C Change Base
D Equation
G Fermat square prime
Last updated
Was this helpful?