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 }
  • 相关阅读:
    editable : false与 readonly 的区别
    Ubuntu环境下使用Jupyter Notebook查找桌面.csv文档的方法
    实验01——java模拟银行ATM系统
    Wannafly挑战赛26 御坂网络
    Wannafly挑战赛29 御坂美琴(递归,模拟)
    牛客练习赛31 龙魂合一萨坎与晶石
    牛客练习赛31
    Codeforces Round #520 (Div. 2)A. A Prank
    (花里胡哨)New Game!(牛客国庆集训派对Day1)
    Educational Codeforces Round 54 (Rated for Div. 2)A. Minimizing the String(签到题)
  • 原文地址:https://www.cnblogs.com/LLGemini/p/4324237.html
Copyright © 2011-2022 走看看