标签:blog io os sp on 2014 log bs amp
就是……判断p与圆心的连线与圆的交点在不在圆弧上,在就是它到p的距离,不在就是p跟端点的最短距离
#include<iostream> #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #include<algorithm> using namespace std; const double pi=acos(-1.0); struct dot { double x,y; dot(){} dot(double a,double b){x=a;y=b;} dot operator +(dot a){return dot(x+a.x,y+a.y);} dot operator -(dot a){return dot(x-a.x,y-a.y);} dot operator *(double a){return dot(x*a,y*a);} double operator *(dot a){return x*a.y-y*a.x;} dot operator /(double a){return dot(x/a,y/a);} double operator /(dot a){return x*a.x+y*a.y;} bool operator ==(dot a){return x==a.x&&y==a.y;} dot norv(){return dot(-y,x);} dot univ(){double a=mod();return dot(x/a,y/a);} dot ro(double a){return dot(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a));} double mod(){return sqrt(x*x+y*y);} double dis(dot a){return sqrt(pow(x-a.x,2)+pow(y-a.y,2));} friend istream & operator >> (istream &is,dot &a) { is>>a.x>>a.y; return is; } friend ostream & operator << (ostream &os,dot a) { os<<a.x<<" "<<a.y; return os; } }; dot o,a,b,c,p; double r; void cg() { dot A,B,C; A=a-o; B=b-o; C=c-o; if(A*B<0) { if(A*C<0&&B*C>0) return; } else { if(!(A*C>0&&B*C<0)) return; } swap(a,c); } double work() { dot A,B,C; A=a-o; B=p-o; C=c-o; if(A*B<0) { if(A*C<0&&B*C>0) return fabs(r-p.dis(o)); } else { if(!(A*C>0&&B*C<0)) return fabs(r-p.dis(o)); } return min(p.dis(a),p.dis(c)); } void cor() { double A,B,C,D,E,F,G,H,I; A=2*(a.x-b.x); B=2*(a.y-b.y); C=pow(a.x,2)-pow(b.x,2)+pow(a.y,2)-pow(b.y,2); D=2*(a.x-c.x); E=2*(a.y-c.y); F=pow(a.x,2)-pow(c.x,2)+pow(a.y,2)-pow(c.y,2); G=dot(A,D)*dot(B,E); H=dot(C,F)*dot(B,E); I=dot(A,D)*dot(C,F); o=dot(H/G,I/G); r=o.dis(a); } int main() { int jishu=0; double ans; while(cin>>a>>b>>c>>p) { cor(); cg(); ans=work(); printf("Case %d: %.3f\n",++jishu,ans); } }
csu 1503: 点到圆弧的距离-湖南省第十届大学生计算机程序设计竞赛
标签:blog io os sp on 2014 log bs amp
原文地址:http://blog.csdn.net/stl112514/article/details/40629877