您的位置:首页 > 其它

Fishnet--计算几何

2016-08-19 11:45 281 查看
Fishnet

Time Limit: 1000MSMemory Limit: 10000K
Total Submissions: 2132Accepted: 1343
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.



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
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
2
0.2000000 0.6000000
0.3000000 0.8000000
0.1000000 0.5000000
0.5000000 0.6000000
2
0.3333330 0.6666670
0.3333330 0.6666670
0.3333330 0.6666670
0.3333330 0.6666670
4
0.2000000 0.4000000 0.6000000 0.8000000
0.1000000 0.5000000 0.6000000 0.9000000
0.2000000 0.4000000 0.6000000 0.8000000
0.1000000 0.5000000 0.6000000 0.9000000
2
0.5138701 0.9476283
0.1717362 0.1757412
0.3086521 0.7022313
0.2264312 0.5345343
1
0.4000000
0.6000000
0.3000000
0.5000000
0

Sample Output
0.215657
0.111112
0.078923
0.279223
0.348958


题目链接:http://poj.org/problem?id=1408

poj初级训练计划我的最后一题,我的天,前两天看了题解并没有看懂,然后就放下了,然后就一直放到了最后,我的天,今天又想了半天,然而我太渣。。。。我很奇怪都已经到小数点后六位了,但是他并没有涉及到精度问题,我的代码你会惊讶的发现和网上的大神差不多,不过我已经懂了思路,果然,大神就是大神,口中的水题我并不会做。。。。

链上大神的博客吧,讲的太仔细了。

http://blog.csdn.net/lyy289065406/article/details/6648592

我的天,懂了之后才发现原来这个题这么简单,但是那个用叉积和定比分点来求交点的那里并不是很懂。。。。上篇计算几何的博客就没懂,问了菊苣们,然而菊苣们并没有给我讲懂。。。。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
struct node
{
double x,y;
};
double chacheng(double x1,double y1,double x2,double y2)//计算叉积
{
return x1*y2-x2*y1;
}
double cross(struct node A,struct node B,struct node C,struct node D)//叉积的板子
{
return chacheng(B.x-A.x,B.y-A.y,D.x-C.x,D.y-C.y);
}
double xx,yy;
void intersection(struct node A,struct node B,struct node C,struct node D)//利用叉积和定比分点求交点
{//然而这个函数只是会用板子,并不懂原理,还要继续研究啊
double area1=cross(A,B,A,C);
double area2=cross(A,B,A,D);
xx=(area2*C.x-area1*D.x)/(area2-area1);
yy=(area2*C.y-area1*D.y)/(area2-area1);
return ;
}
double area(struct node A,struct node B,struct node C,struct node D)//计算面积
{
double s1=fabs(0.5*cross(A,B,A,C));//一定要有绝对值,因为叉积计算的面积可能会有负值
double s2=fabs(0.5*cross(A,B,A,D));
return s1+s2;
}
struct node xin[1000][1000];
int main()
{
int i,j;
int n;
while(~scanf("%d",&n)&&n)
{
xin[0][0].x=0.0;//下边
xin[0][0].y=0.0;
for(i=1;i<=n;i++)
{
scanf("%lf",&xin[0][i].x);
xin[0][i].y=0.0;
}
xin[0][n+1].x=1.0;
xin[0][n+1].y=0.0;
xin[n+1][0].x=0.0;//上边
xin[n+1][0].y=1.0;
for(i=1;i<=n;i++)
{
scanf("%lf",&xin[n+1][i].x);
xin[n+1][i].y=1.0;
}
xin[n+1][n+1].x=1.0;
xin[n+1][n+1].y=1.0;
for(i=1;i<=n;i++)//左边
{
scanf("%lf",&xin[i][0].y);
xin[i][0].x=0.0;
}
for(i=1;i<=n;i++)//右边
{
scanf("%lf",&xin[i][n+1].y);
xin[i][n+1].x=1.0;
}
for(j=1;j<=n;j++)//计算交点坐标
{
for(i=1;i<=n;i++)
{
intersection(xin[0][j],xin[n+1][j],xin[i][0],xin[i][n+1]);
xin[i][j].x=xx;
xin[i][j].y=yy;
}
}
double maxc=0.0;
for(i=1;i<=n+1;i++)//计算面积
{
for(j=1;j<=n+1;j++)
{
double temp=area(xin[i-1][j-1],xin[i][j],xin[i][j-1],xin[i-1][j]);
if(maxc<temp)
maxc=temp;
}
}
printf("%.6f\n",maxc);
}
return 0;
}


我的poj初级训练计划上的另一个计算方法的那个题到现在没有搞懂。。。好难啊QAQ TAT|||
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: