您的位置:首页 > 其它

uva 11314 - Hardly Hard(坐标系问题)

2014-04-30 15:22 323 查看
题目链接:uva 11314 - Hardly Hard

题目大意:给出A,B两点,然后分别在y轴和x轴找一个D点和C点,使得A,B,C和D组成的四边形的周长最小。

解题思路:两点之间直线最短,将A'为A关于y轴的对称点,B'为B关于x轴的对称点,连接A‘B'即为另外三条边的最短距离,然后AB的距离又是固定的。



#include <cstdio>
#include <cstring>
#include <cmath>

double xa, ya, xb, yb;

double distant(double x, double y) {
return sqrt(x*x + y*y);
}

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