HDU 3103 Shoring Up the Levees(计算几何 搜寻区域)

主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3103

Problem Description

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

Source

2008 ACM-ICPC Southeast USA Regional

题意:

给出四个点,连接对角线后,分为四个象限。依照面积大小依次输出,假设面积同样则依照周长大小输出(注意:比較面积是否同样是比較保留了三位后是否同样);

代码例如以下:

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const double eps = 1e-5;
const double PI = acos(-1.0);

struct point
{
    double x, y;
};
struct gao
{
    double mz,zc;
};
struct gao gg[10];

bool cmp(gao a,gao b)
{
    if(a.mz!=b.mz)
        return a.mz>b.mz;
    return a.zc>b.zc;
}
double xmult(double x1,double y1,double x2,double y2,double x0,double y0)
{
    return (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0);
}

//判两点在线段同側,点在线段上返回0
int same_side(point p1,point p2,point l1,point l2)
{
    return xmult(l1.x,l1.y,p1.x,p1.y,l2.x,l2.y)*xmult(l1.x,l1.y,p2.x,p2.y,l2.x,l2.y)>0;
}

//两点距离
double dis(point a,point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
//两线段的交点
point intersection(point u1,point u2,point v1,point v2)
{
    point ret=u1;
    double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
             /((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
    ret.x+=(u2.x-u1.x)*t;
    ret.y+=(u2.y-u1.y)*t;
    return ret;
}

//三点面积
double aera(point a,point b,point c)
{
    double aa,bb,cc,q;
    aa=dis(c,b);
    bb=dis(a,c);
    cc=dis(b,a);
    q=(aa+bb+cc)/2;
    double h=sqrt(q*(q-aa)*(q-bb)*(q-cc));
    h=(int)(h*1000+0.5);
    return h*0.001;
}

//三点周长
double get_zc(point a,point b,point c)
{
    double aa,bb,cc,q;
    aa=dis(c,b);
    bb=dis(a,c);
    cc=dis(b,a);
    q=(aa+bb+cc);
    return q;
}

int main()
{
    int i;
    double x1,y1,x2,y2,x3,y3,x4,y4;
    point a,b,c,d,e;
    while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF)
    {
        if(x1==0 && y1==0 && x2==0 && y2==0 && x3==0 && y3==0 && x4==0 && y4==0)
            break;
        a.x=x1;
        a.y=y1;
        b.x=x2;
        b.y=y2;
        c.x=x3;
        c.y=y3;
        d.x=x4;
        d.y=y4;
        if(same_side(a, b, c,d)==0)
            e = intersection(d,c,a,b);
        else if(same_side(d, b, c, a)==0)
            e = intersection(d,b,c,a);
        else
            e = intersection(b,c,d,a);
        gg[0].mz=aera(a,b,e);
        gg[1].mz=aera(b,c,e);
        gg[2].mz=aera(c,d,e);
        gg[3].mz=aera(a,d,e);
        gg[0].zc=get_zc(a,b,e);
        gg[1].zc=get_zc(b,c,e);
        gg[2].zc=get_zc(c,d,e);
        gg[3].zc=get_zc(a,d,e);
        sort(gg,gg+4,cmp);
        for(i=0; i<3; i++)
            printf("%.3lf %.3lf ",gg[i].mz,gg[i].zc);
        printf("%.3lf %.3lf\n",gg[i].mz,gg[i].zc);
    }
    return 0;
}
/*
2 0 2 2 0 2 0 0
*/

版权声明:本文博主原创文章,博客,未经同意不得转载。

时间: 2024-10-08 15:06:29

HDU 3103 Shoring Up the Levees(计算几何 搜寻区域)的相关文章

HDU 3103 Shoring Up the Levees(计算几何 求面积)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3103 Problem Description 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 t

HDU 1798 Tell me the area (计算几何)

Tell me the area Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1801    Accepted Submission(s): 542 Problem Description There are two circles in the plane (shown in the below picture), there is

HDU 4791 Alice&#39;s Print Service(2013长沙区域赛现场赛A题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3...表示打印区间s1到s2张纸的单价是p1,打印区间s2 到s3的单价是p2....最后是sn到无穷大的单价是pn,让你求打印k张纸的总费用最少是多少?有m次查询. 因为s1*p1 > s2 * p2 > s3*p3......,很显然,加入k所在的那个区间是第x个区间,那么最低费用要么是k * p

HDU 6697 Closest Pair of Segments (计算几何 暴力)

2019 杭电多校 10 1007 题目链接:HDU 6697 比赛链接:2019 Multi-University Training Contest 10 Problem Description The closest pair of points problem is a well-known problem of computational geometry. In this problem, you are given \(n\) points in the Euclidean plan

【HDU 1687】Lucky Light(思维+计算几何)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1687 题意:有一个光源,下面有很多放置的板子,问光线被板子分割之后在地上能产生多少块亮区(看题中的图就能看懂). 分析:这个题的做法和省选第一天的C题很像,由于是求在地面上,也就是一条直线上的亮区,我们可以求出地面上被木板遮挡形成的暗区的左坐标和右坐标,然后合并区间就可以了.而求地面上的坐标,可以用相似三角形,若光源为(sx,sy),点为(x1,y1)和(x2,y2),则地面上的坐标为:sx-(sx-

hdu - 5128 The E-pang Palace(枚举+计算几何)

http://acm.hdu.edu.cn/showproblem.php?pid=5128 给出n个点,求n个点组成两个矩形的最大面积. 矩形必须平行x轴,并且不能相交,但是小矩形在大矩形内部是可以的,面积就为大矩形的面积. 我是枚举一条对角线,然后去找另外两个点是否在坐标中存在这样就可以确定一个矩形, 同理可以枚举出另外有一个矩形,但是要注意坐标不能重复, 判断矩形相交的话,只要判断一个矩形的4个点是否有在另一个矩形的范围内即可. 1 #include<cstdio> 2 #include

HDU 5533 Dancing Stars on Me 计算几何瞎暴力

Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1184    Accepted Submission(s): 651 Problem Description The sky was brushed clean by the wind and the stars were cold in a b

【HDU 5839】Special Tetrahedron(计算几何)

空间的200个点,求出至少四边相等,且其余两边必须不相邻的四面体的个数. 用map记录距离点i为d的点有几个,这样来优化暴力的四重循环. 别人的做法是枚举两点的中垂面上的点,再把到中点距离相等的点找出来,n^3的样子. 还要注意四个点共面的情况. 共面判断就是用叉乘计算出ijk三点所在面的法向量,然后判断il向量是否和法向量垂直,是则共面. #include <cstdio> #include <cstring> #include <algorithm> #includ

HDU 5122 K.Bro Sorting(2014北京区域赛现场赛K题 模拟)

这题定义了一种新的排序算法,就是把一串序列中的一个数,如果它右边的数比它小 则可以往右边移动,直到它右边的数字比它大为止. 易得,如果来模拟就是O(n^2)的效率,肯定不行 想了一想,这个问题可以被转化成 求这一串序列当中每个元素,它的右边是否存在小于它的数字,如果存在,则++ans 一开始没想到诶= = 不应该不应该 1 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler 2 #include <std