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;
}
随机推荐
- Jquery实现的Tabs标签页
效果图: HTML: <div class="tabs"> <ul id="tabs"> <li class="tab- ...
- == 和 isEqualToString的区别之备忘
== 比较的是指针 isEqualToString 比较的是指针指向的内容 比如: NSString * strA = @"abc"; NSString * strB = @&qu ...
- [__NSCFString absoluteURL]错误的解决方案
Xcode提醒错误: -[__NSCFString absoluteURL]: unrecognized selector sent to instance 0x8c4d3a0 *** Termina ...
- SharePoint开发 - 自定义页面(错误页、登出页)
博客地址 http://blog.csdn.net/foxdave 本文叙述如何自定义SharePoint的固有页面,比较简单,用一句话说就是"做个页面,写一句代码." 创建Sha ...
- Oracle GoldenGate 12c 新特性
针对Oracle 12c的专门优化: 针对Oracle数据库的集成交付模式:提升在oracle DB中目标端的交付速度: 针对非Oracle数据库的协调交付模式:降低非oracle DB中多线程配置的 ...
- 第一课 Hello
using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; ...
- hdu 1069
//Accepted 264 KB 0 ms //每种block只有三种方法,且每种放法至多放一次 //规定三条边的顺序后 //把所有的block按x递增排序,x相同则按y递增排序 //然后dp // ...
- IOS NSInvocation用法简介
IOS NSInvocation用法简介 2012-10-25 19:59 来源:博客园 作者:csj007523 字号:T|T [摘要]在 iOS中可以直接调用某个对象的消息方式有两种,其中一种就是 ...
- 排版字号对应多少pt
各字号对应多少pt?初号= 42pt: 小初号= 36pt: 一号= 26pt: 二号= 22pt: 小二号= 18pt: 三号= 16pt: 四号= 14pt: 小四号= 12pt: 五号= 10. ...
- HDU5534--Partial Tree (完全背包)
点击打开链接 思路:总度数为2n-2,由于每个节点都至少要有1个度,所以可以看做把剩余n-2个点放入n个节点的背包问题.dp[i]表示放入i个度后的最大值 #include<cstdio> ...