Doors 2016香港现场赛

https://open.kattis.com/problems/doors

判断一下各个顶点到另一条边的距离就行了

注意不要漏了下面那个门的端点到上面那条边的距离

#include<bits/stdc++.h>
using namespace std;

const double eps=1e-10;
const double pi=acos(-1.0);

inline int sgn(double x)
{
  if(x>-eps && x<eps) return 0;
  if(x>0) return 1;
  else return -1;
}
inline double mysqrt(double x)
{
  return sqrt(max(0.0,x));
}

struct point
{
  double x,y;
  point(double a=0,double b=0)
  {
    x=a;y=b;
  }
  point operator - (const point &b)const
  {
    return point(x-b.x,y-b.y);
  }
  double norm()
  {
    return mysqrt(x*x+y*y);
  }
};
inline double det(const point &a,const point &b)
{
  return a.x*b.y-a.y*b.x;
}
inline double dot(const point &a,const point &b)
{
  return a.x*b.x+a.y*b.y;
}
inline double dist(const point &a,const point &b)
{
  return (a-b).norm();
}
inline double dis_point_seg(const point &p,const point &s,const point &t)
{
  if(sgn(dot(p-s,t-s))<0) return (p-s).norm();
  if(sgn(dot(p-t,s-t))<0) return (p-t).norm();
  return fabs(det(s-p,t-p)/dist(s,t));
}

double R,l,w,ans;
double A,B;

inline void prework()
{
  scanf("%lf%lf",&A,&B);
}

inline void mainwork()
{
  ans=min(l,w);ans=min(ans,R*2);
  point p,s,t;
  p=point(0,w);s=point(l,w);t=point(l+l*cos(pi-A),w+l*sin(pi-A));
  ans=min(dis_point_seg(p,s,t),ans);
  p=point(l+l*cos(pi-B),0+l*sin(pi-B));
  ans=min(dis_point_seg(p,s,t),ans);
  s=point(l,w);t=point(10000,w);
  ans=min(dis_point_seg(p,s,t),ans);
  p=point(l,w);s=point(l,0);t=point(l+l*cos(pi-B),0+l*sin(pi-B));
  ans=min(dis_point_seg(p,s,t),ans);
  
}

inline void print()
{
  printf("%.9f\n",ans/2);
}

int main()
{
  scanf("%lf%lf%lf",&R,&l,&w);
  int t;
  scanf("%d",&t);
  for(int i=1;i<=t;i++)
    {
      prework();
      mainwork();
      print();
    }
  return 0;
}

猜你喜欢

转载自blog.csdn.net/liufengwei1/article/details/108370557
今日推荐