[ACM_几何] Fishnet
本题大意:有一个1X1的矩形,每边按照从小到大的顺序给n个点如图,然后对应连线将举行划分,求最大面积。
解题思路:暴力算出各点,求出各面积
#include<iostream>
#include<cmath>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<iomanip> using namespace std;
#define eps 0.0000000001
#define PI acos(-1.0) //点和向量
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-(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator*(Vector a,double p){return Vector(a.x*p,a.y*p);}
Vector operator/(Vector a,double p){return Vector(a.x/p,a.y/p);}
bool operator<(const Vector& a,const Vector& b){return a.x<b.x||(a.x==b.x && a.y<b.y);}
int dcmp(double x){
if(fabs(x)<eps)return ;
else return x< ? -:;
}
bool operator==(const Point& a,const Point& b){
return dcmp(a.x-b.x)== && dcmp(a.y-b.y)==;
}
double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//向量点积
double Length(Vector A){return sqrt(Dot(A,A));}//向量模长
double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));}//向量夹角
double Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;}
double Area2(Point A,Point B,Point C){return Cross(B-A,C-A);}//三角形面积的2倍
//绕起点逆时针旋转rad度
Vector Rotate(Vector A,double rad){
return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
double torad(double jiao){return jiao/*PI;}//角度转弧度
double tojiao(double ang){return ang/PI*;}//弧度转角度
//单位法向量
Vector Normal(Vector A){
double L=Length(A);
return Vector(-A.y/L,A.x/L);
}
//点和直线
struct Line{
Point P;//直线上任意一点
Vector v;//方向向量,他的左边对应的就是半平面
double ang;//极角,即从x正半轴旋转到向量v所需的角(弧度)
Line(){}
Line(Point p,Vector v):P(p),v(v){ang=atan2(v.y,v.x);}
bool operator<(const Line& L)const {
return ang<L.ang;
}
};
//计算直线P+tv和Q+tw的交点(计算前必须确保有唯一交点)即:Cross(v,w)非0
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;
}
//点到直线距离(dis between point P and line AB)
double DistanceToLine(Point P,Point A,Point B){
Vector v1=B-A , v2=P-A;
return fabs(Cross(v1,v2))/Length(v1);
}
//dis between point P and segment AB
double DistancetoSegment(Point P,Point A,Point B){
if(A==B)return Length(P-A);
Vector v1=B-A,v2=P-A,v3=P-B;
if(dcmp(Dot(v1,v2))<)return Length(v2);
else if(dcmp(Dot(v1,v3))>)return Length(v3);
else return fabs(Cross(v1,v2))/Length(v1);
}
//point P on line AB 投影点
Point GetLineProjection(Point P,Point A,Point B){
Vector v=B-A;
return A+v*(Dot(v,P-A)/Dot(v,v));
}
//线段规范相交(只有一个且不在端点)每条线段两端都在另一条两侧,(叉积符号不同)
bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2){
double c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-a1),
c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1);
return dcmp(c1)*dcmp(c2)< && dcmp(c3)*dcmp(c4)<;
}
//判断点P是否在线段AB上
bool OnSegment(Point p,Point a1,Point a2){
return dcmp(Cross(a1-p,a2-p))== && dcmp(Dot(a1-p,a2-p))<;
}
//多边形的面积(可以是非凸多边形)
double PolygonArea(Point* p,int n){
double area=;
for(int i=;i<n-;i++)
area+=Cross(p[i]-p[],p[i+]-p[]);
return area/;
} //点p在有向直线左边,上面不算
bool OnLeft(Line L,Point p){
return Cross(L.v,p-L.P)>;
} double ok(double x,double y,double d,double z){
double f=fabs(d*(/tan(acos(z/y))+/tan(acos(z/x))))-z;
if(fabs(f)<1e-)return ;
else return f;
}
//计算凸包输入点数组p,个数n,输出点数组ch,返回凸包定点数
//输入不能有重复,完成后输入点顺序被破坏
//如果不希望凸包的边上有输入点,把两个<=改成<
//精度要求高时,建议用dcmp比较
//基于水平的Andrew算法-->1、点排序2、删除重复的然后把前两个放进凸包
//3、从第三个往后当新点在凸包前进左边时继续,否则一次删除最近加入的点,直到新点在左边
int ConVexHull(Point* p,int n,Point*ch){
sort(p,p+n);
int m=;
for(int i=;i<n;i++){//下凸包
while(m> && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-;i>=;i--){//上凸包
while(m>k && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)m--;
ch[m++]=p[i];
}
if(n>)m--;
return m;
}
int main(){
Point point[][];
Point a[],b[],c[],d[];
for(int n;cin>>n&&n;){ point[][].x=;
point[][].y=;
for(int i=;i<n;i++){
cin>>a[i].x;
a[i].y=;
point[][i+]=a[i];
} point[n+][n+].x=;
point[n+][n+].y=;
for(int i=;i<n;i++){
cin>>b[i].x;
b[i].y=;
point[n+][i+]=b[i];
} point[n+][].x=;
point[n+][].y=;
for(int i=;i<n;i++){
cin>>c[i].y;
c[i].x=;
point[i+][]=c[i];
} point[][n+].x=;
point[][n+].y=;
for(int i=;i<n;i++){
cin>>d[i].y;
d[i].x=;
point[i+][n+]=d[i];
} for(int i=;i<n;i++){
for(int j=;j<n;j++){
point[i+][j+]=GetLineIntersection(c[i],d[i]-c[i],a[j],b[j]-a[j]);
}
} Point four[];
double max=-,area;
for(int i=;i<=n;i++){
for(int j=;j<=n+;j++){
four[]=point[i][j];
four[]=point[i][j+];
four[]=point[i+][j+];
four[]=point[i+][j];
area=PolygonArea(four,);
if(area>max)max=area;
}
}
cout<<fixed<<max<<'\n';
}return ;
}
[ACM_几何] Fishnet的更多相关文章
- [ACM_几何] Metal Cutting(POJ1514)半平面割与全排暴力切割方案
Description In order to build a ship to travel to Eindhoven, The Netherlands, various sheet metal pa ...
- [ACM_几何] UVA 11300 Spreading the Wealth [分金币 左右给 最终相等 方程组 中位数]
Problem A Communist regime is trying to redistribute wealth in a village. They have have decided to ...
- [ACM_几何] The Deadly Olympic Returns!!! (空间相对运动之最短距离)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28235#problem/B 题目大意: 有两个同时再空间中匀速运动的导弹,告诉一个时间以 ...
- [ACM_几何] F. 3D Triangles (三维三角行相交)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28235#problem/A 题目大意:给出三维空间两个三角形三个顶点,判断二者是否有公共 ...
- [ACM_几何] Wall
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28417#problem/E 题目大意:依次给n个点围成的一个城堡,在周围建围墙,要求围墙 ...
- [ACM_几何] Pipe
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28417#problem/B 本题大意: 给定一个管道上边界的拐点,管道宽为1,求 ...
- [ACM_暴力][ACM_几何] ZOJ 1426 Counting Rectangles (水平竖直线段组成的矩形个数,暴力)
Description We are given a figure consisting of only horizontal and vertical line segments. Our goal ...
- [ACM_几何] Transmitters (zoj 1041 ,可旋转半圆内的最多点)
Description In a wireless network with multiple transmitters sending on the same frequencies, it is ...
- Fishnet(几何)
http://poj.org/problem?id=1408 题意:给出 a1 a2 ... an b1 b2 ... bn c1 c2 . ...
随机推荐
- cassandra-执行请求入口函数
参考 http://ju.outofmemory.cn/entry/115864 org.apache.cassandra.transport.Message中静态Dispatcher的 channe ...
- linux下不同服务器间数据传输(rcp,scp,rsync,ftp,sftp,lftp,wget,curl)(zz)
linux下不同服务器间数据传输(rcp,scp,rsync,ftp,sftp,lftp,wget,curl) 分类: linux2011-10-10 13:21 8773人阅读 评论(1) 收藏 举 ...
- myeclipse项目编码方式彻底设置
我们团队6月10号开始做龙泉瓯江青瓷有限公司的ERP系统,采用java语言开发,在开发时我们采用的是java的流行框架struts2,前端脚本都用jquery框架,开发IDE用的是myeclipse, ...
- [转]SQL Server表锁定原理以及如何解除锁定
2010年10月13日 12:46 来源:部松昌的博客 作者:部松昌 编辑:胡铭娅 一: 下面以AdventureWorks2008为示例数据库做简要的说明,过滤掉一般的数据库的共享锁, 作为示例必须 ...
- 在Linux上安装最新版java的JDK
之前写过一篇关于MC建服的文章(http://www.cnblogs.com/apollospotatolikett/p/6149042.html),文章中使用的JDK不是最新的版本,当时没有细说如何 ...
- Spring aop 原始的工作原理的理解
理解完aop的名词解释,继续学习spring aop的工作原理. 首先明确aop到底是什么东西?又如何不违单一原则并实现交叉处理呢? 如果对它的认识只停留在面向切面编程,那就脏了.从oop(Objec ...
- Struts1 action重定向跳转 带参数
ActionForward forward = new ActionForward("kmRentalMain.do?method=view&fdId="+id);forw ...
- Spring学习笔记 1. 尚硅谷_佟刚_Spring_HelloWorld
1,准备工作 (1)安装spring插件 搜索https://spring.io/tools/sts/all就可以下载最新的版本 下载之后不用解压,使用Eclipse进行安装.在菜单栏最右面的Help ...
- MySQL的安装配置
安装配置 MySQL1.官方下载 MySQL2.用 tar 解压.tar.bz 或.tar.gz3.解压后有三个目录,分别为 usr etc var4.进入 usr,进入 bin5.在主机上建个目录( ...
- C代码工具--自动生成enum值和名字映射代码
这年头好像继续做C语言的人不多了,年轻人大多去互联网和移动应用.确实,那两个领域现在来钱快,且总是供不应求.就说刚刚在一个旧同事的微信群里,有人刚放出自己有团队可以做App几分钟,哇塞,好几个人说有项 ...