主题链接: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

题意:

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

代码例如以下:

#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
*/

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

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

  1. HDU 5572 An Easy Physics Problem (计算几何+对称点模板)

    HDU 5572 An Easy Physics Problem (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5572 Descripti ...

  2. hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

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

    2019 杭电多校 10 1007 题目链接:HDU 6697 比赛链接:2019 Multi-University Training Contest 10 Problem Description T ...

  4. HDU 1392 Surround the Trees(凸包*计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...

  5. HDU 3264 Open-air shopping malls (计算几何-圆相交面积)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...

  6. hdu 1392:Surround the Trees(计算几何,求凸包周长)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. hdu 1140:War on Weather(计算几何,水题)

    War on Weather Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  8. hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)

    Mirror and Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. hdu 1756:Cupid's Arrow(计算几何,判断点在多边形内)

    Cupid's Arrow Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

随机推荐

  1. WPF界面设计技巧(1)—不规则窗体图文指南

    原文:WPF界面设计技巧(1)-不规则窗体图文指南 初到园子,奉上第一篇入门级教程,请勿见笑. 以往WinForm编程中,实现不规则窗体是有一定难度的,更难的是不规则窗体的边缘抗锯齿及局部透明处理.而 ...

  2. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第15章节--开发SP2013工作流应用程序 总结

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第15章节--开发SP2013工作流应用程序 总结         在SP2013中,工作流已经从SP Server中脱离 ...

  3. 在自己的base脚本中实现自动补全

    在90年代Linux和DOS共存的年代里,Linux的Shell们有一个最微不足道但也最实用的小功能,就是命令自动补全.而DOS那个笨蛋一直到死都没学会什么叫易用. Linux的这个微不足道的小传统一 ...

  4. Oracle连接池

    原由:许多用户可能在查询相同的数据库以获取相同的数据.在这些情况下,可以通过使应用程序共享到数据源的连接来提高应用程序的性能.否则,让每个用户打开和关闭单独的连接的开销会对应用程序性能产生不利影响.这 ...

  5. hdu 4857 逃生 拓扑排序+PQ,剥层分析

    pid=4857">hdu4857 逃生 题目是求拓扑排序,但不是依照字典序最小输出,而是要使较小的数排在最前面. 一開始的错误思路:给每一个点确定一个优先级(该点所能到达的最小的点) ...

  6. 构造Nexus,仓库部署成员Nexus仓

    在一个,我们描述了如何配置安装nexus制,本节,我们来介绍nexus采用 1.登录 在红色的部分点击登陆.输入username与password admin/admin123. 这里能够配置nexu ...

  7. 基于三星ARM9(S3C2410)的交通违章抓拍系统的开发

    ARM9的交通违章抓拍系统的开发   ARM9的交通违章抓拍系统的开发 智能交通系统(ITS)将先进的信息技术.数据通讯传输技术.电子控制技术.计算机处理技术等应用于交通运输行业,从而实现各种运输方式 ...

  8. Cocos性能优化工具的开发介绍Visual Studio内存泄漏检测工具——Visual Leak Detector

    然后,Windows下有什么好的内存泄漏检測工具呢?微软提供Visual Studio开发工具本身没有什么太好的内存泄漏检測功能.我们能够使用第三方工具Visual Leak Detector(下面简 ...

  9. EasyUI基础searchbox&amp;progressbar(搜索框,进度条)

    easyui学习的基本组成部分(八个部分)硕果仅存searchbox和pargressbar.tooltip该,有一点兴奋.本文将偏向searchbox和pargressbar做一个探讨.鉴于双方的内 ...

  10. Linux安装jdk 8和环境变量配置

    1.下载jdk 地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2.将刚刚 ...