2014-07-30 http://acm.hdu.edu.cn/showproblem.php?pid=2528
解题思路:
  求多边形被一条直线分成两部分的面积分别是多少。因为题目给的直线一定能把多边形分成两部分,所以就不用考虑多边形是否与直线相交。直接求问题。
  
  将多边形的每一条边与直线判断是否相交。若相交,就从这点开始计算面积,直到判断到下一个边与直线相交的点。这之间的面积求出来为area2。
  area1为多边形的总面积。多边形被直线分成的另外一部分面积 = area1 - area2   有一个特殊的情况:当直线与多边形的顶点相交时,应该考虑下如何处理 1 #include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std; #define MAXN 30
#define EPS 0.00000001 int dcmp(double x){
if(fabs(x) < EPS)
return ;
return x < ? - : ;
} struct Point{
double x, y;
Point(double x = , double y = ): x(x), y(y) {} bool operator != (const Point & other){
return dcmp(x - other.x) != || (dcmp(x - other.x) == && dcmp(y - other.y) != );
}
}; struct Line{
Point A, B;
//Line(Point A = Point(0, 0), Point B = Point(0, 0)): A(A), B(B){}
}; typedef Point Vector; Vector operator + (Vector A, Vector B){
return Vector(A.x + B.x, A.y + B.y);
} Vector operator - (Point A, Point B){
return Vector(A.x - B.x, A.y - B.y);
} Vector operator * (Vector A, double d){
return Vector(A.x * d, A.y * d);
} Vector operator / (Vector A, double d){
return Vector(A.x / d, A.y / d);
} double dot(Vector A, Vector B){//点乘
return A.x * B.x + A.y * B.y;
} double cross(Vector A, Vector B){//叉乘
return A.x * B.y - A.y * B.x;
} int n;
Point p[MAXN];
Line line; bool input(){
scanf("%d", &n );
if(!n){
return false;
}
for(int i = ; i < n; i++ ){
scanf("%lf%lf", &p[i].x, &p[i].y );
}
scanf("%lf%lf%lf%lf", &line.A.x, &line.A.y, &line.B.x, &line.B.y );
return true;
} double polygon_area(){//求多边形面积
double area = ;
for(int i = ; i < n - ; i++ ){
area += cross(p[i] - p[], p[i + ] - p[]);
}
return fabs(area) * 0.5;
} bool line_segment_intersect(Line L, Point A, Point B, Point &P){//直线和线段相交
Vector a = A - L.B, b = L.A - L.B, c = B - L.B;
if(dcmp(cross(a, b)) * dcmp(cross(b, c)) >= ){//若直线和线段相交 求出交点 《算法入门经典训练之南》上的公式
Vector u = L.A - A;
double t = cross(A - B, u) / cross(b, A - B);
P = L.A + b * t;
return true;
}
return false;
} void solve(){
int flag = ;
double area1 = polygon_area(), area2 = ;//area1算出多边形总面积
Point P, T; p[n] = p[];
for(int i = ; i < n; i++ ){
if(flag == && line_segment_intersect(line, p[i], p[i + ], P)){//第一次相交点
area2 += cross(P, p[i + ]);
flag++;
}else if(flag == && line_segment_intersect(line, p[i], p[i + ], T) && P != T){//第二次相交点
area2 += cross(p[i], T);
area2 += cross(T, P);
flag++;
break;
}else if(flag == ){
area2 += cross(p[i], p[i + ]);
}
}
area2 = fabs(area2) * 0.5;
area1 -= area2;//area1 获取多边形另外一半的面积
if(area1 < area2){//规定大面积在前面 输出
swap(area1, area2);
}
printf("%.0lf %.0lf\n", area1, area2);
} int main(){
//freopen("data.in", "r", stdin );
while(input()){
solve();
}
return ;
}

hdu 2528 Area的更多相关文章

  1. hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)

    Area Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. hdu 2892 Area

    http://acm.hdu.edu.cn/showproblem.php?pid=2892 解题思路: 求多边形与圆的相交的面积是多少. 以圆心为顶点,将多边形划分为n个三角形. 接下来就求出每个三 ...

  3. hdu 4946 Area of Mushroom(凸包)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946 Area of Mushroom Time Limit: 2000/1000 MS (Java/Ot ...

  4. HDU 4946 Area of Mushroom(构造凸包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946 题目大意:在一个平面上有n个点p1,p2,p3,p4....pn,每个点可以以v的速度在平面上移 ...

  5. HDU 4946 Area of Mushroom 凸包

    链接:pid=4946">http://acm.hdu.edu.cn/showproblem.php?pid=4946 题意:有n个人.在位置(xi,yi),速度是vi,假设对于某个点 ...

  6. HDU 4946 Area of Mushroom 凸包 第八次多校

    题目链接:hdu 4946 题意:一大神有N个学生,各个都是小神,大神有个二次元空间,每一个小神都有一个初始坐标,如今大神把这些空间分给徒弟们,规则是假设这个地方有一个人比谁都先到这,那么这个地方就是 ...

  7. hdu 1451 Area in Triangle(计算几何 三角形)

    Given a triangle field and a rope of a certain length (Figure-1), you are required to use the rope t ...

  8. HDU 4946 Area of Mushroom(2014 Multi-University Training Contest 8)

    思路: 只有速度最大才有可能为1,速度不是最大肯定为0,那么就是 只需要操作那些速度最大的点,这些点求一个凸包,判断一下是不是在凸包边上即可. 有几个需要注意的地方: 1.最大速度如果为0   那么肯 ...

  9. HDU 4946 Area of Mushroom (几何凸包)

    题目链接 题意:给定n个人,每个人有一个速度v方向任意.如果平面中存在一个点只有某个人到达的时间最短(即没有人比这个人到的时间更短或相同),那么我们定义这个店归这个人管辖,现在问这些人中哪些人的管辖范 ...

随机推荐

  1. The world beyond batch: Streaming 101

    https://www.oreilly.com/ideas/the-world-beyond-batch-streaming-101 https://www.oreilly.com/ideas/the ...

  2. 【转】在C#用HttpWebRequest中发送GET/HTTP/HTTPS请求

    http://zhoufoxcn.blog.51cto.com/792419/561934 这个需求来自于我最近练手的一个项目,在项目中我需要将一些自己发表的和收藏整理的网文集中到一个地方存放,如果全 ...

  3. [dpdk] 读官方文档(2)

    续前节.切好继续: 一,文档里提到uio_pci_generic, igb_uio, vfio_pci三个内核模块,完全搞不懂,以及dpdk-devbind.py用来查看网卡状态,我得到了下边的输出: ...

  4. jQuery插件之Wookmark瀑布流

    使用方法: 1.下载wookmark.js 2.构建html <div class="wrapper"> <div id="con1_1"&g ...

  5. [LeetCode]题解(python):062 Unique path

    题目来源 https://leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m x  ...

  6. Keep Alive

    跳板机时经常出现连接被断开的情况.如果发生这种情况,请在客户端配置Keep Alive设置,具体方法参考如下: Windows: secureCRT:Properties -> Terminal ...

  7. linux i2c tools

    最近要操作eeprom,所以了解一下i2c-tool的使用方法,记录于此. 参考链接: http://www.myir-tech.com/bbs/thread-7567-1-1.html http:/ ...

  8. SWD模式连接与注意事项

    JTAG模式与SWD模式连接图 SWD 仿真模式概念简述 一.SWD 和传统的调试方式区别 1. SWD 模式比 JTAG 在高速模式下面更加可靠. 在大数据量的情况下面 JTAG 下载程序会失败, ...

  9. C#中override和overload的区别

    重载应该叫overload,重写叫override:重载某个方法是在同一个类中发生的!重写是在子类中重写父类中的方法. 1.override:   父类:public virtual string T ...

  10. Java: Class Variable/Static Variable

    1. Class Variable/Static Variable: Class variable is also known as static variable with "static ...