首页 > 代码库 > csu 1503: 点到圆弧的距离-湖南省第十届大学生计算机程序设计竞赛
csu 1503: 点到圆弧的距离-湖南省第十届大学生计算机程序设计竞赛
就是……判断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: 点到圆弧的距离-湖南省第十届大学生计算机程序设计竞赛
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。