C - Shoring Up the Levees

The tiny country of Waterlogged is protected by a series of levees that form a quadrilateral as shown below: 
 



The quadrilateral is defined by four vertices. The levees partition the country into four quadrants. Each quadrant is identified by a pair of vertices representing the outside edge of that quadrant. For example, Quadrant 1 shown below is defined by the points (x1, y1) and (x2, y2) . 
 



It happens very often that the country of Waterlogged becomes flooded, and the levees need to be reinforced, but their country is poor and they have limited resources. They would like to be able to reinforce those levees that encompass the largest area first, then the next largest second, then the next largest third, and the smallest area fourth. 

Help Waterlogged identify which quadrants are the largest, and the length of the levees around them.

Input

here will be several sets of input. Each set will consist of eight real numbers, on a single line. Those numbers will represent, in order: 


X1 Y1 X2 Y2 X3 Y3 X4 Y4 


The four points are guaranteed to form a convex quadrilateral when taken in order -- that is, there will be no concavities, and no lines crossing. Every number will be in the range from -1000.0 to 1000.0 inclusive. No Quadrant will have an area or a perimeter smaller than 0.001. End of the input will be a line with eight 0.0's.

Output

For each input set, print a single line with eight floating point numbers. These represent the areas and perimeters of the four Quadrants, like this: 


A1 P1 A2 P2 A3 P3 A4 P4 


Print them in order from largest area to smallest -- so A1 is the largest area. If two Quadrants have the same area when rounded to 3 decimal places, output the one with the largest perimeter first. Print all values with 3 decimal places of precision (rounded). Print spaces between numbers. Do not print any blank lines between outputs.

Sample Input

1 2 1 5 5 2 2 0
3.5 2.2 4.8 -9.6 -1.2 -4.4 -8.9 12.4
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

Sample Output

5.100 11.459 3.400 9.045 0.900 6.659 0.600 4.876
44.548 38.972 21.982 25.997 20.342 38.374 10.038 19.043

 

四边形由四个顶点定义。堤坝把这个国家分成四个象限。每个象限由代表该象限外边缘的一对顶点标识。例如,下图中的象限1由点(x1, y1)和(x2, y2)定义。经常发生的情况是,被水淹没的国家被淹没,堤坝需要加固,但他们的国家很穷,资源有限。他们希望能够加固那些首先覆盖最大区域的堤坝,然后是第二大堤,第三大堤,第四小堤。帮助被淹的人识别哪个象限是最大的,以及它们周围堤坝的长度。输入这里有几组输入。每个集合由8个实数组成,在一行上。这些数字将按下列顺序表示:X1 Y1 X2 Y2 X3 Y3 X4 Y4按顺序取四个点,保证形成一个凸四边形,即不存在孔洞,不存在直线交叉。每个数字的范围从-1000.0到1000.0(包括)。没有一个象限的面积或周长小于0.001。输入的末尾是一行8个0.0。输出对于每个输入集,打印一行包含8个浮点数的代码。这些代表了四个象限的面积和周长,就像这样:A1 P1 A2 P2 A3 P3 A4 P4按从大到小的顺序打印——A1是最大的面积。如果两个象限的面积相同,四舍五入到小数点后3位,首先输出周长最大的那个。打印精度为3位小数(四舍五入)的所有值。

题意:给你4个点的坐标  让你求分割成的四块面积的大小和周长 

 

要求按照面积由大到小输出  ,要注意的是 如果面积的小数点后3位以前的值都相等 ,那么默认他们一样大,周长靠前的先输出

要注意的是要考虑精度问题!!!!!

精度问题:计算公式要最简,否则double会出错,还有最后比较的是四舍五入之后的小数

#include<cstdio>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
#define maxn 20010
struct note
{
    double C,s;
} op[4];
int cmp(note op,note oo)
{
     if((int)((op.s+0.0005)*1000)==(int)((oo.s+0.0005)*1000))  //四舍五入保留三位
        return op.C>oo.C;
    return op.s>oo.s;
}
int main()
{
    double x1,x2,x3,x4,y1,y2,y3,y4;
    while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4))
    {
        if(x1==0.0&&x2==0.0&&x3==0.0&&x4==0.0&&y1==0.0&&y2==0.0&&y3==0.0&&y4==0.0)break;
        double a,b,c,d,e,f,g,h,p1,p2,p3,p4,x,y;
        x=((x1*y3-y1*x3)*(x2-x4)-(y4*x2-x4*y2)*(x1-x3))/((y2-y4)*(x1-x3)-(y1-y3)*(x2-x4));
        y=((y2-y4)*(x1*y3-x3*y1)-(y1-y3)*(x2*y4-x4*y2))/((x4-x2)*(y1-y3)-(x3-x1)*(y2-y4));    //根据两条直线求交点,公式要化为最简!否则会wa
        a=sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));
        b=sqrt((x2-x)*(x2-x)+(y2-y)*(y2-y));
        c=sqrt((x3-x)*(x3-x)+(y3-y)*(y3-y));
        d=sqrt((x4-x)*(x4-x)+(y4-y)*(y4-y));
        e=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
        f=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
        g=sqrt((x1-x4)*(x1-x4)+(y1-y4)*(y1-y4));
        h=sqrt((x4-x3)*(x4-x3)+(y4-y3)*(y4-y3));
        op[0].C=a+b+f;
        op[1].C=b+c+e;
        op[2].C=d+c+h;
        op[3].C=a+d+g;
        p1=op[0].C/2.0;
        op[0].s=sqrt(p1*(p1-a)*(p1-b)*(p1-f));
        p2=op[1].C/2.0;
        op[1].s=sqrt(p2*(p2-b)*(p2-c)*(p2-e));
        p3=op[2].C/2.0;
        op[2].s=sqrt(p3*(p3-d)*(p3-c)*(p3-h));
        p4=op[3].C/2.0;
        op[3].s=sqrt(p4*(p4-a)*(p4-d)*(p4-g));
        sort(op,op+4,cmp);
        for(int i=0; i<4; i++)
        {
            printf("%.3lf %.3lf",op[i].s,op[i].C);
            if(i!=3)
                printf(" ");
        }
        printf("\n");
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值