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;
}
题目大意:给出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;
}
相关文章推荐
- UVA 11314 - Hardly Hard(数论)
- UVA - 12558 Egyptian Fractions (HARD version) : 埃及分数问题 IDA*
- UVa OJ The Blocks Problem 木块问题 101
- UVa11624(逃离火焰问题)
- C - Underwater Snipers UVALive - 5000 最小值最大化问题 二分
- UVa1262 - Password(解码问题)
- uva 816 BFS求最短路的经典问题……
- uva 147 - Dollars 钱币兑换问题(浮点数) 精度问题 完全背包
- uva11134 fabled rooks 贪心+问题独立分解
- (UVa 11997)K Smallest Sums --多路归并问题,优先队列
- 例10-9 uva1636简单概率问题
- uva11134 - Fabled Rooks(问题分解,贪心法)
- 找规律(约瑟夫的数论问题,uva 1363)
- SDUT 2080 最长公共子序列问题 (同uva10100 && POJ 1458 && HDU 1159)
- UVA 10652 - Board Wrapping 几何问题之凸包(附凸包模板)
- opengl中关于平移旋转坐标系问题
- HDU 2069 & UVA 674 Coin Change(换硬币 dp 入门经典水题,背包问题)
- 【山外智能车】【IAR】【编译问题】HardFault_Handler
- 汉诺塔相关,递归(新汉诺塔问题,uva 10795)
- UVAlive 2519 Radar Installation (区间选点问题)