Problem H

HARDLY HARD

You have been given the task of cutting out a quadrilateral slice of cake out of a larger, rectangular cake. You must find the slice with the smallest perimeter that satisfies the following constraints. If the cake is of size 10000-by-10000 units and is represented using the first quadrant of the Cartesian plane, then your slice is quadrilateral ABCD (see figure). Points A and B are fixed and will be given to you. Also, A,B will lie on a negatively sloping line. Furthermore, points C and D must lie on the positive y-axis and positive x-axis respectively, but it is up to you to determine where these two points should be. A,B,C,D will be distinct points.

Output the minimum perimeter of your slice of cake.

Input

On the first line you will be given n (1 ≤ n ≤ 100), the number of test cases. The following n lines each contain ax ay bx by (0 < ax, ay, bx, by ≤ 10000.0), the coordinates of points A and B respectively.

Output

For each test case, output the perimeter accurate to 3 decimal places on its own line.

题意:由一个矩形蛋糕切出一个四边形,要求周长最小;其中A,B两点坐标已给出,且C,D点要求在x,y轴正半轴。

分析:以x,y轴作对称点连接。证明很好证,两点之间线段最短嘛。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define error 1e-8
using namespace std;
const int maxn = ; double Get_len(double x1, double y1, double x2, double y2)
{
return sqrt((y2-y1)*(y2-y1) + (x2-x1)*(x2-x1));
}
int main()
{ int T;
scanf("%d", &T);
while(T--)
{
double ax, ay, bx, by;
scanf("%lf%lf%lf%lf", &ax, &ay, &bx, &by);
if(by < ay) {swap(ay, by); swap(ax, bx);}
double cx=ax, cy=-ay, dx=-bx, dy=by;
printf("%.3lf\n", Get_len(cx, cy, dx, dy)+Get_len(ax, ay, bx, by));
}
return ;
}

最新文章

  1. COGS732. [网络流24题] 试题库
  2. html内容超出了div的宽度如何换行让内容自动换行
  3. 第二章Java基础之标识符
  4. 如何用 OneAPM 优化你的 Node.js 应用?
  5. [百度]数组A中任意两个相邻元素大小相差1,在其中查找某个数
  6. ClassNotFoundException
  7. epoll 回显服务器源码
  8. xpath应用
  9. Mantis的附件图片实现预览/弹出层动画效果预览图片(LightBox2)的完美解决方案[Z]
  10. call_grant_dml.sql
  11. AVL树(Java实现)
  12. 虚拟机与Docker有何不同?
  13. linq的基本使用
  14. Ubuntu中创建Python虚拟环境
  15. Dubbo高可用
  16. TECH books
  17. JSTL、JSTL核心标签库——流程处理标签
  18. 基于用Path.Combine的优化
  19. Linux 简单命令查询CPU、内存、网卡等信息
  20. 关于sys.dm_exec_requests

热门文章

  1. JSF 2 listbox example
  2. jQuery弹性滑动导航菜单实现思路及代码
  3. 认识JavaScript的原型
  4. c# 如何使用DLL的config文件中的信息
  5. VC的文件操作
  6. List、ArrayList、Vector及map、HashTable、HashMap分别的区别
  7. CSS 文本格式
  8. Bootstrap 列偏移\列嵌套\列排序
  9. c#与java webservice调用问题
  10. 发现一个挺好用的adb logcat工具