hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)
Area
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 225 Accepted Submission(s): 77
清水河校区位于成都高新西区的中部地带,占地约3128亩。从空中看,新校区的整体像一个长方形,南北长,东西窄。一条水渠从西北角的顶点注入,笔直的延伸到南面围墙的大概三分之一分点的地方,由此流出学校。位于这条水渠和西墙之间的是研究院,最南面的是学术交流中心和接待中心。
在本题中,假设清水河校区是一个凸多边形,水渠是一条直线,要求给出清水河校区被水渠分割成的两部分的面积。
对于一个顺时针给出的多边形,如果它的顶点坐标依次是(xi,yi),0<=i<n,则它的面积为:
#include <iostream>
#include <cmath>
using namespace std;
#define eps 1e-10
/********** 定义点 **********/
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
};
/********** 定义向量 **********/
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 b)
{
return Vector(a.x*b,a.y*b);
}
/********** 2向量求叉积 **********/
double Cross(Vector a,Vector b)
{
return a.x*b.y-b.x*a.y;
}
int dcmp(double x) //减少精度问题
{
if(fabs(x)<eps)
return ;
else
return x<?-:;
}
/********** 直线交点 **********/
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)
{
Vector u = P-Q;
double t = Cross(w,u) / Cross(v,w);
return P+v*t;
}
/********* 求多边形面积 **********/
double ConvexPolygonArea(Point* p,int n)
{
double area = ;
for(int i=;i<=n-;i++)
area += Cross(p[i]-p[],p[i+]-p[]);
return area/;
}
int main()
{
int n;
while(cin>>n){
if(n==) break;
int i;
Point p[];
for(i=;i<=n;i++)
cin>>p[i].x>>p[i].y;
Point p0,p1;
cin>>p0.x>>p0.y>>p1.x>>p1.y;
Vector v = p1-p0;
Point pl[]; //切割后的多边形之一
p[n+] = p[];
int num = ;
//产生切割多边形
for(i=;i<=n;i++){
int d1 = dcmp(Cross(v,p[i]-p0));
int d2 = dcmp(Cross(v,p[i+]-p0));
if(d1>=)
pl[++num] = p[i];
if(d1*d2<)
pl[++num] = GetLineIntersection(p0,v,p[i],p[i+]-p[i]);
}
double a1 = fabs(ConvexPolygonArea(pl,num));
double sum = fabs(ConvexPolygonArea(p,n));
double a2 = sum-a1; int A1 = int(fabs(a1)+0.5);
int A2 = int(fabs(a2)+0.5);
if(A1>=A2)
cout<<A1<<' '<<A2<<endl;
else
cout<<A2<<' '<<A1<<endl;
}
return ;
}
Freecode : www.cnblogs.com/yym2013
hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)的更多相关文章
- hdu 1086 You can Solve a Geometry Problem too 求n条直线交点的个数
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- hdu 2528 Area
2014-07-30 http://acm.hdu.edu.cn/showproblem.php?pid=2528解题思路: 求多边形被一条直线分成两部分的面积分别是多少.因为题目给的直线一定能把多边 ...
- HDU 1754 I Hate It 线段树单点更新求最大值
题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...
- POJ 1039 Pipe【经典线段与直线相交】
链接: http://poj.org/problem?id=1039 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)
Mirror and Light Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
- POJ 1039 Pipe(直线和线段相交判断,求交点)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8280 Accepted: 2483 Description ...
- MATLAB—求直线或者线段之间的交点坐标
function CrossPoint( ) %% 求两条直线的交点坐标 x1 = [7.8 8]; y1 = [0.96 0.94]; %line2 x2 = [8.25 8.25]; y2 = [ ...
- poj 1654 Area(计算几何--叉积求多边形面积)
一个简单的用叉积求任意多边形面积的题,并不难,但我却错了很多次,double的数据应该是要转化为long long,我转成了int...这里为了节省内存尽量不开数组,直接计算,我MLE了一发...,最 ...
随机推荐
- How to make a custom WIDGET in OpenERP
转自:http://sahotaparamjitsingh.blogspot.com/2012/04/how-to-make-custom-widget-in-openerp.html Hello ...
- servlet request getQueryString 汉字的URI编码如何转码
JavaScript中编码有三种方法:escape.encodeURI.encodeURIComponent,地址栏中那些%XX就是汉字对应的字节被encodeURI编码格式转了.一个字节对应一个% ...
- Android API之android.view.View.MeasureSpec
android.view.View.MeasureSpec MeasureSpec是View的内部类 public static class MeasureSpec MeasureSpec封装从par ...
- windows中mongoDB安装教程
下载路径:http://downloads.mongodb.org/win32/mongodb-win32-i386-1.7.0.zip 将一个DB文件夹 我是放到D盘,路径:Ddb 解压mongod ...
- atitit。解决 No suitable Log constructor。。NoClassDefFoundError: org/apache/log4j/Category 找不到类的
atitit.解决 No suitable Log constructor..NoClassDefFoundError: org/apache/log4j/Category 找不到类的 1. 深的层次 ...
- android.view.animation(1) - alpha、scale、translate、rotate、set的xml属性和用法(转)
一.ScaleAnimation ScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, floa ...
- Lucene用法10个小结 (zhuan)
http://www.cfanz.cn/index.PHP?c=article&a=read&id=303149 *********************************** ...
- rsync 精确同步文件用法 (转载)
-- include-from 指定目录下的部分目录的方法: include.txt: aa bb ss Command: rsync -aSz --include-from=/home/inclu ...
- maven 引入 net sf jsonlib 报错 has borken path
pom.xml 内容: <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json ...
- dp之多重背包hdu1059
题意:价值为1,2,3,4,5,6. 分别有n[1],n[2],n[3],n[4],n[5],n[6]个.求能否找到满足价值刚好是所有的一半的方案. 思路:简单的多重背包,我建议多重背包都用二进制拆分 ...