Ural_1348. Goat in the Garden 2(计算几何)
2011-10-28 22:09
597 查看
乱搞题,就是看仔细不仔细了。代码很水,分好几种情况。
c所在的位置分三种情况,分别计算;ab那条线段也可能是平行x轴或y轴,也分别计算。
My Code:
c所在的位置分三种情况,分别计算;ab那条线段也可能是平行x轴或y轴,也分别计算。
My Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define pi 3.1415926535 using namespace std; struct point{ double x; double y; }; int Abs(double x){ return x > 0 ? x : -x; } int main(){ //freopen("data.in", "r", stdin); double l, A, B, C, k, t; double d1, d2, y; point a, b, c, tmp; scanf("%lf%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y, &l); if(a.y > b.y) {tmp = a; a = b; b = tmp;} A = b.y - a.y; B = a.x - b.x; C = a.y*(b.x - a.x) - a.x*(b.y - a.y); d1 = sqrt((c.y - a.y)*(c.y - a.y) + (c.x - a.x)*(c.x - a.x)); d2 = sqrt((c.y - b.y)*(c.y - b.y) + (c.x - b.x)*(c.x - b.x)); if(a.y == b.y){ if(a.x < b.x) {tmp = a; a = b; b = tmp;} if(c.x > a.x || c.x < b.x){ d1 -= l; d2 -= l; if(d2 < d1) {t = d1; d1 = d2; d2 = t;} printf("%.2lf\n%.2lf\n", d1>0?d1:0, d2>0?d2:0); } else { d1 -= l; d2 -= l; d2 = d2 > d1 ? d2 : d1; d1 = Abs(c.y - a.y); d1 -= l; printf("%.2lf\n%.2lf\n", d1>0?d1:0, d2>0?d2:0); } }else if(a.x == b.x){ if(c.y < a.y || c.y > b.y){ d1 -= l; d2 -= l; if(d2 < d1) {t = d1; d1 = d2; d2 = t;} printf("%.2lf\n%.2lf\n", d1>0?d1:0, d2>0?d2:0); }else{ d1 -= l; d2 -= l; d2 = d2 > d1 ? d2 : d1; d1 = Abs(c.x - a.x); d1 -= l; printf("%.2lf\n%.2lf\n", d1>0?d1:0, d2>0?d2:0); } }else{ k = (a.y - b.y)/(a.x - b.x); k = -1/k; y = k*c.x + a.y - k*a.x; if(c.y < y){ d1 -= l; d2 -= l; if(d2 < d1) {t = d1; d1 = d2; d2 = t;} printf("%.2lf\n%.2lf\n", d1>0?d1:0, d2>0?d2:0); }else{ y = k*c.x - b.y - k*b.x; if(c.y > y){ d1 -= l; d2 -= l; if(d2 < d1) {t = d1; d1 = d2; d2 = t;} printf("%.2lf\n%.2lf\n", d1>0?d1:0, d2>0?d2:0); }else{ d1 -= l; d2 -= l; d2 = d2 > d1 ? d2 : d1; d1 = Abs(A*c.x + B*c.y + C)/sqrt(A*A + B*B); d1 -= l; printf("%.2lf\n%.2lf\n", d1>0?d1:0, d2>0?d2:0); } } } return 0; }
相关文章推荐
- URAL 1348 Goat in the Garden 2计算几何(解题报告)
- Ural-1084. Goat in the Garden(计算几何)
- Ural 1084|Goat in the Gardon|计算几何
- GYM 100488 A. Yet Another Goat in the Garden(计算几何)
- URAL 1348. Goat in the Garden 2[求点到线段的距离]
- ural 1348. Goat in the Garden 2
- 【点到线段距离】URAL - 1348 Goat in the Garden 2
- URAL Goat in the Garden(圆与矩形求交集面积)
- SPOJ 149 FSHEEP Fencing in the Sheep ( 计算几何 + 二分 )
- ural 1084 Goat in the Garden
- Goat in the Garden (ural 1348)
- ural 1084 Goat in the Garden
- URAL 1348 Goat in the Garden 2(点到线段的距离)
- Ural_1207. Median on the Plane(计算几何)
- Ural1084. Goat in the Garden
- URAL 1084 || Goat in the Garden(同中心矩形与圆的公共面积
- ural 1348 Goat in the Garden 2
- URAL 1348 Goat in the Garden 2(点到线段的距离)
- Ural 1207. Median on the Plane(计算几何)
- URAL 1750 Pakhom and the Gully 计算几何+floyd