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 }
  • 相关阅读:
    .NE 学习概要
    (转)工作之路---记录LZ如何在两年半的时间内升为PM
    XP下Winform背景透明问题
    CSE(Corrupted State Exceptions) 严重异常处理办法
    (转)C#模拟键盘鼠标事件
    (转).net项目技术选型总结
    (转)MSMQ续
    (转)MSMQ(消息队列)
    (转)TCP三次握手
    Socket编程初探
  • 原文地址:https://www.cnblogs.com/LLGemini/p/4324237.html
Copyright © 2011-2022 走看看