UVA 11314 - Hardly Hard(数论)

时间:2014-04-27 17:40:22   收藏:0   阅读:555

题目链接: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;
}


UVA 11314 - Hardly Hard(数论),码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!