Fishnet - UVa 1301 几何
来源:互联网 发布:淘宝提升转化率 编辑:程序博客网 时间:2024/05/16 06:06
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 (Figure 1). 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 one 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 ofpegs are represented by their (x, y) -coordinates. Those of an example case with n = 2 are depicted in Figures 2 and 3. The position of the i th 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 that the wood-frame is thin enough for neglecting its thickness.
Input
The input consists of multiple subproblems followed by a line containing a zero that indicates the end of input. Each subproblem is given in the following format.
n
a1a2 ... an
b1b2 ... bn
c1c2 ... cn
d1d2 ... dn
An integer n followed by a newline is the number of pegs on each edge. a1,..., an , b1,..., bn , c1,..., cn ,d1,..., dn are decimal fractions, and they are separated by a space character except that an, bn, cn and dn are followed by a new line. Each ai (i = 1,..., n) indicates the x -coordinate of the i th peg on the bottom edge. Each bi (i = 1,..., n) indicates the x -coordinate of the i th peg on the top edge. Each ci (i = 1,..., n)indicates the y -coordinate of the i th peg on the left edge. Each di (i = 1,..., n) indicates the y -coordinate of the i th peg on the right edge. The decimal fractions are represented by 7 digits after the decimal point. In addition you may assume that 0 < n30 , 0 < a1 < a2 < ... < an < 1 , 0 < b1 < b2 < ... < bn < 1 , 0 < c1 < c2 < ... < cn < 1 and 0 < d1 < d2 < ... < dn < 1 .
Output
For each subproblem, 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.3000000 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
题意:给你一个(n+1)*(n+1)的网,让你求出最大的四边形的面积。
思路:用几何的两条直线求交点,算出四个端点,然后转化成两个三角形求面积。
AC代码如下:
#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;struct Point{ double x,y; Point(double x=0,double y=0):x(x),y(y){}};typedef Point Vector;double eps=1e-10;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);}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;}double area(Point a,Point b,Point c){return abs(Cross(a,b)+Cross(b,c)+Cross(c,a))/2;}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 a[40],b[40],c[40],d[40];int n;int main(){ int i,j,k; double ans,ret; Point A,B,C,D,_A1,_B1,_C1,_D1,_A2,_B2,_C2,_D2; _A1.y=_A2.y=0; _B1.y=_B2.y=1; _C1.x=_C2.x=0; _D1.x=_D2.x=1; while(~scanf("%d",&n) && n>0) { for(i=1;i<=n;i++) scanf("%lf",&a[i]); for(i=1;i<=n;i++) scanf("%lf",&b[i]); for(i=1;i<=n;i++) scanf("%lf",&c[i]); for(i=1;i<=n;i++) scanf("%lf",&d[i]); n++; a[0]=b[0]=c[0]=d[0]=0; a[n]=b[n]=c[n]=d[n]=1; ans=0; for(i=1;i<=n;i++) for(j=1;j<=n;j++) { _A1.x=a[j-1];_A2.x=a[j]; _B1.x=b[j-1];_B2.x=b[j]; _C1.y=c[i-1];_C2.y=c[i]; _D1.y=d[i-1];_D2.y=d[i]; A=GetLineInterSection(_A1,_B1-_A1,_C1,_D1-_C1); B=GetLineInterSection(_A2,_B2-_A2,_C1,_D1-_C1); C=GetLineInterSection(_A2,_B2-_A2,_C2,_D2-_C2); D=GetLineInterSection(_A1,_B1-_A1,_C2,_D2-_C2); ret=area(A,B,C)+area(A,D,C); ans=max(ans,ret); } printf("%.6f\n",ans); }}
- Fishnet - UVa 1301 几何
- uva 1301 - Fishnet(几何+枚举)
- UVA 1301 Fishnet
- 【计算几何】Fishnet
- Fishnet--计算几何
- POJ Fishnet 1408(计算几何)
- (beginer)线段求交:多边形面积 UVA 1301 - Fishnet
- POJ 1408 Fishnet(计算几何,多边形相关算法)
- poj 1408 Fishnet(计算几何 叉积求面积 求两直线交点 暴力)
- POJ 1408-Fishnet(计算几何-根据交点求多边形面积)
- uva 11524 - InCircle(几何)
- InCircle - UVa 11524 几何
- Hills - UVa 1359 几何
- UVA 11437(几何入门)
- uva 11796 几何模拟
- uva 12300 几何基础
- uva 11186 几何
- uva 11178 计算几何
- windows检测端口的工具-PsTools
- Sicily 2015. A New Year Gift
- 使用Java Socket发送魔术包:实现电脑远程开机(WOL)
- 算法训练 K好数
- android大分辨率图片的缩放处理和图片添加水印+文字,水印图片对角线显示
- Fishnet - UVa 1301 几何
- 用Scheme写一个Scheme编译器(一)
- 动态根据文件创建类,并纳入spring管理
- Sicily 1937. 导游
- ios Objective-C Runtime运行时类与对象的编译处理(写的很好,值得阅读)
- UrbanCode Deploy 常用操作
- 网关协议学习:CGI、FastCGI、WSGI
- (转)被误解的 Node.js
- ws问题总结(二)