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;
}
随机推荐
- Setup Factory 打包.netframework 2.0
在setup factory 的安装目录下的Dependencies中新建目录dotnet20/并放入dotnetfx2.0.exe: Dependencies目录中再加xml文件dotnet20.x ...
- XCode之entitlement
entitlement是codesign的一个输入,参见:codesign. entitlement的意思是权力,也就是表明应用所具有的权利,可以访问什么,不能访问什么等.这些信息会在codesign ...
- poj2129 dp
//Accepted 320 KB 47 ms //dp //dp[i][j]=1 表示用s1的前i个,s2的前j个字符能构成s3的前i+j-1个字符 //dp[i][j]=0 表示构不成 //dp[ ...
- UVa 10328 - Coin Toss (递推)
题意:给你一个硬币,抛掷n次,问出现连续至少k个正面向上的情况有多少种. 原题中问出现连续至少k个H的情况,很难下手.我们可以试着将问题转化一下. 设dp[i][j]表示抛掷i个硬币出现连续至多j个H ...
- spring六种种依赖注入方式
平常的java开发中,程序员在某个类中需要依赖其它类的方法,则通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理,spring提出了依赖注入的思想,即依赖类不由程 ...
- (转)浅析Mysql的my.ini文件
原文:http://blog.csdn.net/heirenheiren/article/details/7895139 转载:http://hunanpengdake.iteye.com/admin ...
- Yii数据库操作增删改查-[增加\查询\更新\删除 AR模式]
在Yii的开发中常常需要去使用Yii的增删改查方法,这些方法又可以多次变化和组合,带来全方位的实现对数据库的处理,下面对这些方法做一些简单的整理和梳理,有遗漏或是BUG,敬请指出.灰常感谢!!! 一. ...
- 学军NOIP2016模拟赛1
GTMD这么水的一套题没有AK T1:妥妥的二分答案,贪心check. T2:问题可以转化为最长上升(还是下降我记不住了)子序列. T3:发现点被覆盖上的顺序是一定的.求出这个顺序,第一个操作在线段树 ...
- Svn win7系统下状态图标不显示-转载
Svn win7系统下状态图标不显示 Svn版本 tortoisesvn-1.8.8.25755-x64-svn-1.8.10.msi 2.不显示图标状态如图1,期望结果显示图标状态如图2 图1 图2 ...
- 头文件定义和ARM指令
2015.2.2星期一,阴天 内存管理:内存的分配和释放等静态和动态内存:主要是在释放方式上的区别 静态变量:编译时就已经确定,定义在函数外面自动变量:在程序运行时才能在栈中确定只读数据节:存放常量的 ...