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-23 06:24: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 1264 Counting Squares(线段树求面积的并)

Counting Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1885    Accepted Submission(s): 946 Problem Description Your input is a series of rectangles, one per line. Each rectangle is sp

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 4405 Aeroplane chess (概率DP求期望)

题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点需要步数的期望 其中有m个跳跃a,b表示走到a点可以直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点可以到走到i+1,i+2,i+3,i+4,i+5,i+6 点且每个点的概率都为1/6 所以dp[i]=(dp[i+1]+dp[i+2]+dp[i+3]+dp[i+4]+dp[i+5]+dp[i+6])/6  + 1(步数加一). 而对于有跳跃的点直接为dp[a]=dp[b]; #include<stdio.h>

HDU 1828 Picture(线段树扫描线求周长)

Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4475    Accepted Submission(s): 2207 Problem Description A number of rectangular posters, photographs and other pictures of the same shap

poj1039——计算几何 求直线与线段交点,判断两条直线是否相交

poj1039——计算几何  求直线与线段交点,判断两条直线是否相交 Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9439   Accepted: 2854 Description The GX Light Pipeline Company started to prepare bent pipes for the new transgalactic light pipeline. During the de

HDU 1517 A Multiplication Game (博弈-求sg)

A Multiplication Game Problem Description Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p = 1, does his multiplication, then Ollie multiplies the number, then Stan and

hdu how many prime numbers 筛选法求素数

/* * hdu How many prime numbers * date 2014/5/13 * state AC */ #include <iostream> #include <cmath> #include <cstdio> using namespace std; bool isPrime(int x) { int sqr=sqrt(x*1.0); for(int i=2;i<=sqr;i++) { if(x%i==0)return false; }

hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。

题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有的连通分量只有一个点,当舍去该点时候,连通分量-1: 复习求割点的好题! #include<iostream> #include<cstdio> #include<vector> using namespace std; int n,m; vector<vector&