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.
Inputhere will be several sets of input. Each set will consist of eight real numbers, on a single line. Those numbers will represent, in order:
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.
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.OutputFor 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.0Sample 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
题意 : 给你4个点的坐标 让你求分割成的四块面积的大小和周长
要求按照面积由大到小输出 ,要注意的是 如果面积的小数点后3位以前的值都相等 ,那么默认他们一样大,周长靠前的先输出
要注意的是要考虑精度问题
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<queue>
#include<set>
#include<algorithm>
#include<math.h>
#define ll long long
using namespace std;
double dis(double x1,double y1,double x2,double y2)//距离
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
const double eps=1e-8;//精度
struct node
{
double l;//周长
double s;//面积
}e[4];
void ss(double l1,double l2,double l3,int i)
{
double l=(l1+l2+l3);
e[i].l=l;
l/=2.0;
e[i].s=sqrt(l*(l-l1)*(l-l2)*(l-l3));//海伦公式计算面积
}
int cmp(node n1,node n2)
{
if(floor(n1.s*1000+eps)==floor(n2.s*1000+eps))//要加eps
return n1.l>n2.l;
return n1.s>n2.s;
}
double l[8];
int main()
{
double x1,y1,x2,y2,x3,y3,x4,y4,a1,a2,b1,b2,c1,c2;
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) return 0;
a1=y1-y3,b1=x3-x1,c1=x1*y3-x3*y1;
a2=y2-y4,b2=x4-x2,c2=x2*y4-x4*y2;
double x=(c2*b1-c1*b2)/(b2*a1-b1*a2);//交点
double y=(a2*c1-a1*c2)/(b2*a1-b1*a2);
// printf("%lf %lf \n",x,y);
l[0]=dis(x1,y1,x2,y2);
l[1]=dis(x1,y1,x4,y4);
l[2]=dis(x3,y3,x4,y4);
l[3]=dis(x2,y2,x3,y3);
l[4]=dis(x,y,x1,y1);
l[5]=dis(x,y,x2,y2);
l[6]=dis(x,y,x3,y3);
l[7]=dis(x,y,x4,y4);
ss(l[0],l[4],l[5],0);
ss(l[1],l[4],l[7],1);
ss(l[2],l[6],l[7],2);
ss(l[3],l[5],l[6],3);
sort(e,e+4,cmp);
for(int i=0;i<4;i++)
{
if(i!=0) printf(" ");
printf("%.3lf %.3lf",e[i].s,e[i].l);
}
printf("\n");
}
}