LA2402暴力枚举+计算几何+四边形面积
2014-02-26 21:00
246 查看
/* LA2402: 题意:在矩形中给定横线(竖)之间不交叉的n对线,求被分割的小块的最大面积 读懂题意就可以发现是思路很简单的题目 枚举+几何计算,时间复杂度度不高 熟悉了部分函数的运用 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <ctype.h> #include <string> #include <iostream> #include <sstream> #include <vector> #include <queue> #include <stack> #include <map> #include <list> #include <set> #include <algorithm> using namespace std; struct Point { double x,y; Point(double x=0,double y=0):x(x),y(y){} void print() { cout<<"("<<x<<","<<y<<")"<<endl; } }; typedef Point Vector; Vector operator-(Point A,Point B)//表示A指向B { return Vector(A.x-B.x,A.y-B.y); } Vector operator*(Vector A,double k) { return Vector(A.x*k,A.y*k); } Vector operator+(Point A,Point B)//表示A指向B { return Vector(B.x+A.x,B.y+A.y); } double Cross(Vector A,Vector B) {return A.x*B.y-A.y*B.x;} double Area(Point A,Point B,Point C)//三角形面积 { return fabs(Cross(B-A,C-A))/2; } struct Line { Point p; Vector v; Line(Point p,Vector v):p(p),v(v){} }; Line Getline(Point A,Point B)//求直线AB { Vector u=A-B; return Line(A,u); } Point InterSection(Line L1,Line L2)//求直线交点 { Vector u=L1.p-L2.p; double t=Cross(L2.v,u)/Cross(L1.v,L2.v); return L1.p+L1.v*t; } double a[50],b[50],c[50],d[50]; int n; int main() { while(cin>>n) { if(!n) break; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++) cin>>b[i]; for(int i=1;i<=n;i++) cin>>c[i]; for(int i=1;i<=n;i++) cin>>d[i]; a[0]=0;b[0]=0;c[0]=0;d[0]=0; a[n+1]=1;b[n+1]=1;c[n+1]=1;d[n+1]=1; double m=-1; for(int i=0;i<=n;i++)//外层枚举相邻的横线 { Line L1=Getline(Point(0,c[i]),Point(1,d[i])); Line L2=Getline(Point(0,c[i+1]),Point(1,d[i+1])); for(int j=0;j<=n;j++)//内层枚举相邻的竖线 { Line L3=Getline(Point(a[j],0),Point(b[j],1));//一开始写成i,= =! Line L4=Getline(Point(a[j+1],0),Point(b[j+1],1)); Point P1=InterSection(L1,L3); Point P2=InterSection(L1,L4); Point P3=InterSection(L2,L4); Point P4=InterSection(L2,L3); double S=Area(P1,P2,P4)+Area(P2,P3,P4); // P1.print();P2.print();P3.print();P4.print(); // cout<<"A1="<<Area(P1,P2,P4)<<endl; // cout<<"A2="<<Area(P2,P3,P4)<<endl; // cout<<"S="<<S<<endl; if (S>m) m=S; } } printf("%.6lf\n",m); } return 0; }
相关文章推荐
- 算法之美——求两直线交点(三维叉积)——求四边形面积(二维叉积)
- BZOJ1069:最大土地面积(旋转卡壳 & 四边形面积)
- Matlab最小面积包围四边形
- (原创题) 四边形面积 (三角函数+余弦定理或者海伦公式)
- python中 自定义向量 计算向量乘积, 平行四边形面积,三角形面积
- 行列式与平行四边形的面积
- 平行四边形的第四个点及其面积
- 边长确定的四边形面积最大值定理
- HDOJ---4242||HNNUOJ Rancher's Gift[四边形分割的面积]
- UVa 10545 Maximal Quadrilateral (有内切圆的四边形面积)
- 【ZOJ3919 2016年浙大2月月赛E】【简单计算几何 贪心】Ellipse 椭圆内切圆外切平行四边形最大最小面积
- 旋转卡壳 求凸多边形中面积最大的四边形
- HDU4386-海伦公式求四边形面积
- 平行四边形面积
- 柱形图中求最大四边形面积
- POJ 1408 Fishnet (判断围成四边形最大面积,直线相交问题)
- 海伦公式与四边形面积公式
- 两个向量(x1, y1), (x2, y2) 之间的平行四边形面积为啥是 (x1*y2-x2*y1)?
- 如何制作平行四边形面积公式推导课件
- 任意四边形的面积公式