Problem H

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.

题意:由一个矩形蛋糕切出一个四边形,要求周长最小;其中A,B两点坐标已给出,且C,D点要求在x,y轴正半轴。

分析:以x,y轴作对称点连接。证明很好证,两点之间线段最短嘛。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define error 1e-8
using namespace std;
const int maxn = ; double Get_len(double x1, double y1, double x2, double y2)
{
return sqrt((y2-y1)*(y2-y1) + (x2-x1)*(x2-x1));
}
int main()
{ int T;
scanf("%d", &T);
while(T--)
{
double ax, ay, bx, by;
scanf("%lf%lf%lf%lf", &ax, &ay, &bx, &by);
if(by < ay) {swap(ay, by); swap(ax, bx);}
double cx=ax, cy=-ay, dx=-bx, dy=by;
printf("%.3lf\n", Get_len(cx, cy, dx, dy)+Get_len(ax, ay, bx, by));
}
return ;
}

【基础数学知识】UVa 11314 - Hardly Hard的更多相关文章

  1. Python之基础数学知识

    一.线性代数 1.求转置 import numpy m = numpy.mat([[1, 2], [3, 4]]) print("Matrix.Transpose:") print ...

  2. 基础数学知识 / Math(updating)

    埃氏筛:朴素筛法求素数,o(nloglogn) int prime[N], tot; bool st[N]; // true:not prime, false:is prime void get_pr ...

  3. HTML5 Canvas核心技术图形动画与游戏开发(读书笔记)----第一章,基础知识

    一,canvas元素 1 为了防止浏览器不支持canvas元素,我们设置“后备内容”(fallback content),下面紫色的字即为后备内容 <canvas id="canvas ...

  4. HTML5中手势原理分析与数学知识的实践

    摘要:在这触控屏的时代,人性化的手势操作已经深入了我们生活的每个部分.现代应用越来越重视与用户的交互及体验,手势是最直接且最为有效的交互方式,一个好的手势交互,能降低用户的使用成本和流程,大大提高了用 ...

  5. [web建站] 极客WEB大前端专家级开发工程师培训视频教程

    极客WEB大前端专家级开发工程师培训视频教程  教程下载地址: http://www.fu83.cn/thread-355-1-1.html 课程目录:1.走进前端工程师的世界HTML51.HTML5 ...

  6. 用CSS变形创建圆形导航

    http://www.w3cplus.com/css3/building-a-circular-navigation-with-css-transforms.html 本文由陈毅根据SARA SOUE ...

  7. 机器学习的数学基础(1)--Dirichlet分布

    机器学习的数学基础(1)--Dirichlet分布 这一系列(机器学习的数学基础)主要包括目前学习过程中回过头复习的基础数学知识的总结. 基础知识:conjugate priors共轭先验 共轭先验是 ...

  8. unity3d 数学的数学基础和辅助类

    转载注明smartdot:http://my.oschina.net/u/243648/blog/67193 1.  数学(点乘/叉乘)/unity3d的数学辅助类 2.  坐标系统(本地/世界/屏幕 ...

  9. AI 学习路线

    [导读] 本文由知名开源平台,AI技术平台以及领域专家:Datawhale,ApacheCN,AI有道和黄海广博士联合整理贡献,内容涵盖AI入门基础知识.数据分析挖掘.机器学习.深度学习.强化学习.前 ...

随机推荐

  1. HDU 5781 ATM Mechine (概率DP)

    ATM Mechine 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 Description Alice is going to take ...

  2. 转载 C#结构体(struct)和类(class)的区别

    转载原地址: http://dotnet.9sssd.com/csbase/art/8 C#结构体和类的区别问题:在C#编程语言中,类属于引用类型的数据类型,结构体属于值类型的数据类型,这两种数据类型 ...

  3. Android:从程序员到架构师之路Ⅲ_高焕堂

    Part-2: 从Android框架代码中学习设计 一 基础设计模式(Pattern)的代码:以Android为例 1.Template Method模式:IoC(控制反转)机制 2.Observer ...

  4. Host key verification failed解决

    SSH 登录失败:Host key verification failed 由于公钥不一样了,所以无法登录,提示信息是 KEY 验证失败. 解决方法是: 在 /root/.ssh/known_host ...

  5. java中动态代理

    一.在java中怎样实现动态代理 1.我们要有一个接口,还要有一个接口的实现类,而这个实现类呢就是我们要代理的对象 接口: package org.dynamicproxy.test; public ...

  6. openssl数字证书常见格式与协议介绍

    原文地址:http://blog.csdn.net/anxuegang/article/details/6157927 证书主要的文件类型和协议有: PEM.DER.PFX.JKS.KDB.CER.K ...

  7. squid添加用户名密码认证

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...

  8. 进入名企必读的.NET面试题

    1. 罗列ASP.NET服务器控件的运行的生命周期. 一般服务器控件的生命周期包含11个阶段: /// <summary> /// 1. 初始化 /// </summary> ...

  9. 【转】Ruby入门教程(一)

    1. Ruby环境搭建 在Windows下,搭建Ruby环境,比较简单的方法是在“RubyInstaller”上下载一个合适的版本(D瓜哥使用的是最新版),直接安装就可以了. 另外,吐槽两句,网上有人 ...

  10. 瑞丽的SQL-基于窗体的排名计算

    在SQL Server中,窗体被定义为用户指定的一组行. 之所以要提出窗体这个概念,由于这种基于窗体或分区的又一次计算在实际工作应用范围比較广泛.比如.假设我们要对每一个班级中的学生按成绩进行排序,在 ...