zoukankan      html  css  js  c++  java
  • 【基础数学知识】UVa 11314

    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轴作对称点连接。证明很好证,两点之间线段最短嘛。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #define error 1e-8
     6 using namespace std;
     7 const int maxn = 10010;
     8 
     9 
    10 double Get_len(double x1, double y1, double x2, double y2)
    11 {
    12     return sqrt((y2-y1)*(y2-y1) + (x2-x1)*(x2-x1));
    13 }
    14 int main()
    15 {
    16 
    17     int T;
    18     scanf("%d", &T);
    19     while(T--)
    20     {
    21         double ax, ay, bx, by;
    22         scanf("%lf%lf%lf%lf", &ax, &ay, &bx, &by);
    23         if(by < ay) {swap(ay, by); swap(ax, bx);}
    24         double cx=ax, cy=-ay, dx=-bx, dy=by;
    25         printf("%.3lf
    ", Get_len(cx, cy, dx, dy)+Get_len(ax, ay, bx, by));
    26     }
    27     return 0;
    28 }
  • 相关阅读:
    详细对比9门主流编程语言
    ZT在谷歌上班感受如何?
    林锐:5 C++/C程序的基本概念
    林锐书:写一个hello world by seasoned professional
    C 中重载一词中的“重”字读ZHONG4还是CHONG2?
    ZT C++ 重载、覆盖和隐藏的区别
    安全模式 冷启动
    Wi-Fi
    再谈男性饮食保健
    fstat、stat和lstat 区别(转)
  • 原文地址:https://www.cnblogs.com/LLGemini/p/4324237.html
Copyright © 2011-2022 走看看