zoukankan      html  css  js  c++  java
  • 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 ",dis(x1,y1,x2,y2)+dis(x1,y1,-x2,-y2));
        }
        return 0;
    }

  • 相关阅读:
    嘿,新年快乐
    最近无状态~
    奥巴马:我们为什么要上学
    大学学不会逃课是不会有出息的!
    赫赫,给红十字捐款的sb了吧
    狄仁杰你敢不装逼吗
    腾讯qq开始耍威胁用户的无赖手段了
    <转>关于信仰
    恩,老了~~~
    Vue 2.0学习笔记: Vue中的computed属性
  • 原文地址:https://www.cnblogs.com/20143605--pcx/p/4667070.html
Copyright © 2011-2022 走看看