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. 1
  2. 3.0 1.0 1.0 2.0

Output for the Sample Input

  1. 7.236
  2.  
  3. 解析:当周长最短时,BCAD都与AB垂直。
  4.  
  5. 代码如下:
    # 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. 腾讯微博数据抓取(java实现)

    不多说,同样贴出相关代码 参数实体: package token.def; import java.io.Serializable; import java.util.Properties; publ ...

  2. Map学习

    1.Query Operations(查询操作) int size();boolean isEmpty(); boolean containsKey(Object key);boolean conta ...

  3. 看项目得到info_freeCsdn-01闪屏页面

    /** * 渐变展示启动屏 */ private void startAnimation() { Animation aa = new Animation() { }; aa.setDuration( ...

  4. bjui简单了解

    bjui官网:http://demo.b-jui.com/ 其他的我就不是很了解,恶心.

  5. Android 自带图标库 android.R.drawable

    在xml文件中调用. android:title="@string/secure_connect"android:orderInCategory="100"an ...

  6. 2013年9月份第2周51Aspx源码发布详情

    休闲农庄企业站源码  2013-9-13 [VS2008]功能介绍:  首页功能:关于我们 资讯中心 休闲娱乐 餐饮娱乐 环境展示 园林展示 交通指引 联系我们  后台功能:      基本信息:服务 ...

  7. 关于高并发的aotomic

    AtomicInteger线程安全的根源,熟悉并发的同学一定知道在java中处理并发主要有两种方式: 1,synchronized关键字,这个大家应当都各种面试和笔试中经常遇到. 2,volatile ...

  8. Java基础毕向东day02

    1. 常量 null 等特殊 2.标识符 数字-字母-下划线,数字不能开头 3.二进制 1> 二进制计算方法. 2>常用二进制. 1        1      0       0   1 ...

  9. hdu1878 欧拉回路

    //Accepted 1240 KB 250 ms //水题 欧拉回路 //连通+节点度均为偶数 #include <cstdio> #include <cstring> #i ...

  10. kali linux karmetasploit配置【续】

    Karmetasploit In Action https://www.offensive-security.com/metasploit-unleashed/karmetasploit-action ...