您的位置:首页 > 其它

UVA 11314 - Hardly Hard(数论)

2014-04-27 11:25 232 查看


题目链接:11314 - Hardly Hard

题意:给定A,B两点,求Y轴上一点C和X轴上一点D,使得该四边形周长最小。
思路:B以Y轴做对称点,A以X轴做对称点,然后两点相连就是其他三边的周长,因为两点间线段最短,然后再加上AB长度即可
代码:
#include <stdio.h>
#include <string.h>
#include <math.h>

int t;
struct Point {
double x, y;
Point() {}
Point(double _x, double _y) {
x = _x; y = _y;
}
void scan() {
scanf("%lf%lf", &x, &y);
}
} a, b, c, d;

double dis(Point a, Point b) {
double x = a.x - b.x;
double y = a.y - b.y;
return sqrt(x * x + y * y);
}

int main() {
scanf("%d", &t);
while (t--) {
a.scan();
b.scan();
c = Point(-b.x, b.y);
d = Point(a.x, -a.y);
printf("%.3lf\n", dis(a, b) + dis(c, d));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: