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.

Sample Input

1
3.0 1.0 1.0 2.0

Output for the Sample Input

7.236

解析:当周长最短时,BC、AD都与AB垂直。

代码如下:
# include<iostream>
# include<cstdio>
# include<cstring>
# include<cmath>
# include<algorithm>
using namespace std;
double dis(double x1,double y1,double x2,double y2)
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
    //freopen("T - Hardly Hard.txt","r",stdin);
    int T;
    double x0,y0,x1,y1,x2,y2;
    scanf("%d",&T);
    while(T--)
    {
        cin>>x1>>y1>>x2>>y2;
        printf("%.3lf\n",dis(x1,y1,x2,y2)+dis(x1,y1,-x2,-y2));
    }
    return 0;
}

随机推荐

  1. DB2使用笔记

    1.赋予用户LOAD权限的步骤   使用实例用户db2inst1登录数据库:     使用命令db2 update dbm cfg using sysadm_group dasadm1给管理员用户组d ...

  2. HTTP状态代码

    1xx(临时响应)表示临时响应并需要请求者继续执行操作的状态代码. 100 (继续) 请求者应当继续提出请求. 服务器返回此代码表示已收到请求的第一部分,正在等待其余部分. 101 (切换协议) 请求 ...

  3. 深入理解dispatch_queue

    Grand Central Dispatch是苹果过去几年创造出来的非常强大的API,在Let's Build系列的最新一期中,我们将探究dispatch_queue基础功能的重新实现.该主题是Rob ...

  4. Android 微信分享图文资料

    上个项目做Android的微信分享,需要分享的内容有图片有文字,看了微信分享的SDK,貌似没有这个API,在网上搜了好久,总算找到解决方法了,直接上代码: public void sendReq(Co ...

  5. 通过使用ScriptManager.RegisterStartupScript,呈现后台多次使用alert方法

    在前台HTML中加入alert或者confirm,相信大家已经非常熟悉并且经常使用: <div onclick="alert('hello')">按钮1</div ...

  6. OpenCV之响应鼠标(一):利用鼠标获取坐标

    好久没有更新博客了,今天临时起意,将以前写的示例代码整理了一下,暂且发布一篇,希望对大家有用! 代码一:点击时显示坐标,鼠标移动时不显示. #include <cv.h> #include ...

  7. Oracle 12c与GoldenGate 12c的一些问答

    1. 如何知道一个12c DB是否为容器数据库?(1) container DBSQL> select cdb from v$database;CDB---YES (2) non contain ...

  8. struts调用的几种方法

    在Struts2中方法调用概括起来主要有三种形式 第一种方式:指定method属性 <action name="student" class="com.itmyho ...

  9. 数组prototype添加函数呢,采用回调判定函数内容

    1.解决方案 Array.prototype.all = function (p) { return this.filter(p).length == this.length; }; Array.pr ...

  10. SAP财务常用数据源概览

    一. 0FI_GL_10总分类账:领先分类账余额 Delta Update : AIED After Images Marked for Deletion via Extractor (FI-GL/A ...