POJ1408-Fishnet(线段求交)
来源:互联网 发布:软件测试佣金问题 编辑:程序博客网 时间:2024/06/11 21:00
Fishnet
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 1788 Accepted: 1144
Description
A fisherman named Etadokah awoke in a very small island. He could see calm, beautiful and blue sea around the island. The previous night he had encountered a terrible storm and had reached this uninhabited island. Some wrecks of his ship were spread around him. He found a square wood-frame and a long thread among the wrecks. He had to survive in this island until someone came and saved him.
In order to catch fish, he began to make a kind of fishnet by cutting the long thread into short threads and fixing them at pegs on the square wood-frame. He wanted to know the sizes of the meshes of the fishnet to see whether he could catch small fish as well as large ones.
The wood frame is perfectly square with four thin edges on meter long: a bottom edge, a top edge, a left edge, and a right edge. There are n pegs on each edge, and thus there are 4n pegs in total. The positions of pegs are represented by their (x,y)-coordinates. Those of an example case with n=2 are depicted in figures below. The position of the ith peg on the bottom edge is represented by (ai,0). That on the top edge, on the left edge and on the right edge are represented by (bi,1), (0,ci) and (1,di), respectively. The long thread is cut into 2n threads with appropriate lengths. The threads are strained between (ai,0) and (bi,1),and between (0,ci) and (1,di) (i=1,...,n).
You should write a program that reports the size of the largest mesh among the (n+1)2 meshes of the fishnet made by fixing the threads at the pegs. You may assume that the thread he found is long enough to make the fishnet and the wood-frame is thin enough for neglecting its thickness.
In order to catch fish, he began to make a kind of fishnet by cutting the long thread into short threads and fixing them at pegs on the square wood-frame. He wanted to know the sizes of the meshes of the fishnet to see whether he could catch small fish as well as large ones.
The wood frame is perfectly square with four thin edges on meter long: a bottom edge, a top edge, a left edge, and a right edge. There are n pegs on each edge, and thus there are 4n pegs in total. The positions of pegs are represented by their (x,y)-coordinates. Those of an example case with n=2 are depicted in figures below. The position of the ith peg on the bottom edge is represented by (ai,0). That on the top edge, on the left edge and on the right edge are represented by (bi,1), (0,ci) and (1,di), respectively. The long thread is cut into 2n threads with appropriate lengths. The threads are strained between (ai,0) and (bi,1),and between (0,ci) and (1,di) (i=1,...,n).
You should write a program that reports the size of the largest mesh among the (n+1)2 meshes of the fishnet made by fixing the threads at the pegs. You may assume that the thread he found is long enough to make the fishnet and the wood-frame is thin enough for neglecting its thickness.
Input
The input consists of multiple sub-problems followed by a line containing a zero that indicates the end of input. Each sub-problem is given in the following format.
n
a1 a2 ... an
b1 b2 ... bn
c1 c2 ... cn
d1 d2 ... dn
you may assume 0 < n <= 30, 0 < ai,bi,ci,di < 1
n
a1 a2 ... an
b1 b2 ... bn
c1 c2 ... cn
d1 d2 ... dn
you may assume 0 < n <= 30, 0 < ai,bi,ci,di < 1
Output
For each sub-problem, the size of the largest mesh should be printed followed by a new line. Each value should be represented by 6 digits after the decimal point, and it may not have an error greater than 0.000001.
Sample Input
20.2000000 0.60000000.3000000 0.80000000.1000000 0.50000000.5000000 0.600000020.3333330 0.66666700.3333330 0.66666700.3333330 0.66666700.3333330 0.666667040.2000000 0.4000000 0.6000000 0.80000000.1000000 0.5000000 0.6000000 0.90000000.2000000 0.4000000 0.6000000 0.80000000.1000000 0.5000000 0.6000000 0.900000020.5138701 0.94762830.1717362 0.17574120.3086521 0.70223130.2264312 0.534534310.40000000.60000000.30000000.50000000
Sample Output
0.2156570.1111120.0789230.2792230.348958
题意:题上的图很明显了。
思路:线段求交(把边上的线段算上),得到的4个点算面积。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <vector>#include <algorithm>using namespace std;#define REP(_,a,b) for(int _ = (a); _ < (b); _++)#define sz(s) (int)((s).size())typedef long long ll;const double eps = 1e-10;const int maxn = 50;int n;struct Point{double x,y;Point(double x=0.0,double y = 0.0):x(x),y(y){}};Point vP[maxn];typedef Point Vector;struct Line {Point P;Vector v;double ang;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;}};Line LX[maxn],LY[maxn];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);}int dcmp(double x){if(fabs(x) < eps) return 0;else return x < 0? -1:1;}bool operator < (const Point &a,const Point &b){return dcmp(a.x-b.x) <0 || dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)<0;}bool operator == (const Point &a,const Point &b){return dcmp(a.x-b.x)==0&& dcmp(a.y-b.y)==0;}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;}Vector Rotate(Vector A,double rad) {return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad)); }Vector Normal(Vector A) {double L = Length(A);return Vector(-A.y/L,A.x/L);}bool OnSegment(Point p,Point a1,Point a2){return dcmp(Cross(a1-p,a2-p)) == 0 && dcmp(Dot(a1-p,a2-p)) < 0;}Point GetIntersection(Line a,Line b){Vector u = a.P-b.P;double t = Cross(b.v,u) / Cross(a.v,b.v);return a.P+a.v*t;}int ConvexHull(Point* p,int n,Point *ch){sort(p,p+n);int m = 0;for(int i = 0; i < n; i++) {while(m > 1 && dcmp(Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])) <= 0) m--;ch[m++] = p[i]; }int k = m;for(int i = n-2; i >= 0; i--){while(m > k && dcmp(Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])) <= 0) m--;ch[m++] = p[i];}if(n > 1) m--;return m;}double a[maxn];void input(){double t;REP(i,0,n)scanf("%lf",&a[i]);LX[0] = Line(Point(0,1.0),Vector(0,-1.0));REP(i,0,n){scanf("%lf",&t);LX[i+1] = Line(Point(t,1.0),Vector(a[i]-t,-1.0));}LX[n+1] = Line(Point(1.0,1.0),Vector(0,-1.0));LY[0] = Line(Point(1.0,0),Vector(-1.0,0));REP(i,0,n)scanf("%lf",&a[i]);REP(i,0,n){scanf("%lf",&t);LY[i+1] = Line(Point(1.0,t),Vector(-1.0,a[i]-t));}LY[n+1] = Line(Point(1.0,1.0),Vector(-1.0,0));}void solve(){double ans = 0;REP(i,1,n+2) {Point a,b,c,d;REP(j,1,n+2) {a = GetIntersection(LX[i-1],LY[j-1]);//cout<<a.x<<" "<<a.y<<endl;b = GetIntersection(LX[i],LY[j-1]);//cout<<b.x<<" "<<a.y<<endl;c = GetIntersection(LX[i],LY[j]);d = GetIntersection(LX[i-1],LY[j]);double area = 0;area = fabs(Cross(a,b)/2+Cross(b,c)/2+Cross(c,d)/2+Cross(d,a)/2);ans = max(area,ans);}}printf("%.6f\n",ans);}int main(){while(~scanf("%d",&n) && n){input();solve();}return 0;}
0 0
- POJ1408-Fishnet(线段求交)
- poj1408--Fishnet(求多边形面积)
- (beginer)线段求交:多边形面积 UVA 1301 - Fishnet
- POJ1408 Fishnet
- poj1408 Fishnet
- POJ1408 两条线段求交点+叉乘求几何面积+枚举
- poj1127线段求交
- 线段与三角形求交
- 线段求交算法demo
- 不简单的【线段求交】
- poj3225(线段树求区间交,并,补)
- HDU1255 覆盖的面积 (线段树求面积交)
- 线段树(求矩形并,交,并减交的面积)
- poj1408
- 线段求交算法对比研究
- 计算几何——线段求交
- poj3304(计算几何+线段求交)
- hdu 1086 计算几何 线段求交
- nfc开发
- STL之list
- 对JDBC的详解
- Android系统自带样式(@android:style/)
- 如何传递参数给Dynamic Region?
- POJ1408-Fishnet(线段求交)
- 基础知识--脚本语言
- 函数参数大盘点
- poj2516Minimum Cost
- 送给圣诞夜的礼品
- servlet中response的几种应用
- 杭电2066————Dijkstra的应用
- hdoj 2093 考试排名 ( 结构体处女作。。花了好长时间的说!)
- 黑马程序员,黑马论坛----- 交通灯一点小疑问