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.
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;
}
随机推荐
- [C/C++]C++声明
[注]本文是Declarations的翻译和注解版. https://msdn.microsoft.com/en-us/library/f432x8c6.aspx 1.声明: 我们通过声明往C++程序 ...
- Centos 6 安装 epel yum库
1.获得epel库安装rpm包 wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm 2.安装获得的r ...
- AutoReleasePool 和 ARC 以及Garbage Collection
AutoReleasePool autoreleasepool并不是总是被auto 创建,然后自动维护应用创建的对象. 自动创建的情况如下: 1. 使用NSThread的detachNewThread ...
- poj2264 dp+路径
//Accepted 208K 0MS //dp //最长公共子序列+路径 #include <cstdio> #include <cstring> #include < ...
- Ubuntu 14.10 下sed命令详解
简介 sed 是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的 ...
- JS - To my gril
/* 这个程序的流程是 , 首先执行 构造函数 (), 然后 就去执行那个 render 渲染 , 在 render 哪里 的if else 转向应该执行的渲染方法 , 例如 commitsrende ...
- svn出现权限不足时的解决方法
将所有svn目录设置为当前用户所有....即可 sudo chown will:will . -R
- array_count_values函数
array_count_values() 函数用于统计数组中所有值出现的次数. 本函数返回一个数组,其元素的键名是原数组的值,键值是该值在原数组中出现的次数. 例子 <?php $a=array ...
- HDU 4160
http://acm.hdu.edu.cn/showproblem.php?pid=4160 大娃娃可以套在小娃娃外面(各边严格小),问最后最少得到几个娃娃 题目中的娃娃可以看做点,嵌套关系可以看做有 ...
- 游戏buff设计参见
其实这类帖子并没有多少的设计理论,对于策划的提升和帮助也并不大,原因其实在于其适用性太窄,当我要设计XX象棋的时候,它就滚一边去了. 废话不多说切入正题: 游戏中的BUFF/DEBUFF我们见过很多, ...