1 条题解
-
0
C++ :
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<string> #include<vector> #include<queue> #include<cmath> #include<set> using namespace std; const double eps = 1e-10; struct Point{ double x, y; Point(){} Point(double x, double y):x(x), y(y){} }; Point operator - (Point a, Point b){ return Point(a.x-b.x, a.y-b.y); } int dcmp(double x){ if(fabs(x) < eps)return 0; return x < 0 ? -1 : 1; } double Cross(Point a, Point b){ return a.x * b.y - a.y * b.x; } bool Segem(Point a1, Point a2, Point b1, Point b2){ double c1 = Cross(a1-b1, b2-b1); double c2 = Cross(a2-b1, b2-b1); double c3 = Cross(b2-a1, a2-a1); double c4 = Cross(b1-a1, a2-a1); return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0; } double Len(Point a, Point b){ double d = (a.x-b.x) * (a.x-b.x) + (a.y-b.y) * (a.y-b.y); return sqrt(d); } int main() { int cas = 1; double x1, y1, x2, y2; Point a, b, c, d; while(~scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2)){ if(x1 + x2 + y1 + y2 == 0)break; a = Point(x1, y1); b = Point(x2, y2); scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2); c = Point(x1, y1); d = Point(x2, y2); double dis = 0; if(Segem(a, b, c, d) == 0){ dis = Len(a, b); } else{ dis = min(Len(a, c) + Len(c, b), Len(a, d) + Len(d, b)); } printf("Case %d: %.3lf\n",cas++, dis / 2); } return 0; }
- 1
信息
- ID
- 739
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者