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. Oracle GoldenGate 12c 新特性

    针对Oracle 12c的专门优化: 针对Oracle数据库的集成交付模式:提升在oracle DB中目标端的交付速度: 针对非Oracle数据库的协调交付模式:降低非oracle DB中多线程配置的 ...

  2. poj3356 dp

    //Accepted 4100 KB 0 ms //类似poj1080 //dp[i][j]表示s1用前i个,s2用前j个的最少匹配步数 //dp[i][j]=min(dp[i][j-1]+1,dp[ ...

  3. 巧用nginx屏蔽对用户不可见的文件

    事情的起因是这样的--前端的项目中有一些.less之类的源文件,而为了方便迭代更新发布,直接就把整个工程放到了www目录下. 这样虽然方便了,但是会带来一些安全隐患——用户可以访问/盗取这些源文件. ...

  4. hdu 2098

    ps:TLE一次....因为判断素数的时候没开方...作死.. 代码: #include "stdio.h" #include "math.h" int inp ...

  5. 2016 - 1- 19 利用多线程优化从网上加载图片的Demo

    // // ZZTableViewController.m // 多图片下载 // // Created by Mac on 16/1/19. // Copyright © 2016年 Mac. Al ...

  6. 2016 - 1 -19 初探NSOperation

    一:简介 1.NSOperation的作用: 配合NSOperation与NSOperationQueue也可以实现多线程. 2.NSOperation与NSOperationQueue实现多线程的步 ...

  7. linux下的文件权限管理

    权限管理有两个层面 第一层区分用户:文件属主(u), 组用户(g), 其它(o) 第二层区分权限:读(r),写(w),可执行(x) 这两个层次构成文件权限管理的二维结构 u         g     ...

  8. USB peripherals can turn against their users

    Turning USB peripherals into BadUSB USB devices are connected to – and in many cases even built into ...

  9. 事件委托 EventHandler

    事件就是当对象或类状态发生改变时,对象或类发出的信息或通知.发出信息的对象或类称为"事件源",对事件进行处理的方法称为"接收者",通常事件源在发出状态改变信息时 ...

  10. Interview----判断整数序列是否是二叉搜索树的后序遍历结果

    题目:输入一个整数数组,判断该数组是不是某二元查找树的后序遍历的结果. 如果是返回true,否则返回false. 例如输入5.7.6.9.11.10.8,由于这一整数序列是如下树的后序遍历结果:   ...