Fishnet(计算几何)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 1642 | Accepted: 1051 |
Description
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
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
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 题意:在一个边长为1的正方形(如图)的四个边上分别插入n个点,上和下,左和右分别对应点相连构成若干个线段,这些线段相交之后构成若干个四边形,问最大的那个四边形的面积;
先将对应点连起来构成线段,求出各个交点,这样就可以根据叉乘求出每个四边形的面积,比较之后得出最大的。我开始存输入的点的坐标时用的一位数组,结果找四边形对应顶点时就很麻烦,还是没想全面。改成二维数组后,p[i][j]就表示第i行第j个点的坐标,这样找四边形顶点坐标就好找了;
#include<stdio.h>
#include<string.h>
#include<math.h> const double eps = 1e-;
int cmp(double x)
{
if(fabs(x) < eps)
return ;
if(x > ) return ;
return -;
} struct point
{
double x,y;
point(){}
point(double a,double b):x(a),y(b) {}
friend point operator - (const point &a, const point &b)
{
return point(a.x-b.x,a.y-b.y);
}
friend point operator * (const double &a, const point &b)
{
return point(a*b.x,a*b.y);
}
friend point operator / (const point &a, const double &b)
{
return point(a.x/b,a.y/b);
}
}p[][];//p[i][j]存第i行第j列交点处的点的坐标; struct line
{
point a,b;
line (){}
line(point x, point y):a(x),b(y) {}
}L[][];//存线段; double det(const point &a, const point &b)
{
return a.x * b.y - a.y * b.x;
}
bool parallel(line a,line b)
{
return !cmp(det(a.a-a.b,b.a-b.b));
}
bool line_make_point(line a,line b,point &res)
{
if(parallel(a,b)) return false;
double s1 = det(a.a-b.a,b.b-b.a);
double s2 = det(a.b-b.a,b.b-b.a);
res = (s1*a.b-s2*a.a)/(s1-s2);
return true;
}
double area(point a[])
{
double sum = ;
a[] = a[];
for(int i = ; i < ; i++)
sum += det(a[i+],a[i]);
return sum/;
}
int main()
{
int n;
while(~scanf("%d",&n) && n)
{
for(int i = ; i <= n; i++)
{
scanf("%lf",&p[][i].x);
p[][i].y = ;
}
p[][].x = ;
p[][].y = ;
p[][n+].x = ;
p[][n+].y = ; for(int i = ; i <= n; i++)
{
scanf("%lf",&p[n+][i].x);
p[n+][i].y = ;
}
p[n+][].x = ;
p[n+][].y = ;
p[n+][n+].x = ;
p[n+][n+].y = ; for(int i = ; i <= n; i++)
{
scanf("%lf",&p[i][].y);
p[i][].x = ;
}
for(int i = ; i <= n; i++)
{
scanf("%lf",&p[i][n+].y);
p[i][n+].x = ;
}
for(int i = ; i <= n; i++)
{
L[i][].a = p[][i];
L[i][].b = p[n+][i];
}
for(int i = ; i <= n; i++)
{
L[][i].a = p[i][];
L[][i].b = p[i][n+];
} for(int i = ; i <= n; i++)
{
for(int j = ; j <= n; j++)
line_make_point(L[][i],L[j][],p[i][j]);//横着第i条线段与竖着第j条线段的交点保存在p[i][j]中
} double max = eps;
for(int i = ; i <= n+; i++)
{
for(int j = ; j <= n+; j++)
{
point t[];
t[] = p[i][j-];
t[] = p[i][j];
t[] = p[i-][j];
t[] = p[i-][j-];//顺时针四个点的坐标;
double sum = area(t);
if(sum > max)
max = sum;
}
}
printf("%.6lf\n",max);
}
return ;
}
Fishnet(计算几何)的更多相关文章
- POJ 1408 Fishnet【枚举+线段相交+叉积求面积】
题目: http://poj.org/problem?id=1408 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)
POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...
- HDU 2202 计算几何
最大三角形 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- ACM 计算几何中的精度问题(转)
http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...
- hdu 2393:Higher Math(计算几何,水题)
Higher Math Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- [知识点]计算几何I——基础知识与多边形面积
// 此博文为迁移而来,写于2015年4月9日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vxaq.html 1.前言 ...
- POJ 1106 Transmitters(计算几何)
题目链接 切计算几何,感觉计算几何的算法还不熟.此题,枚举线段和圆点的直线,平分一个圆 #include <iostream> #include <cstring> #incl ...
- TYVJ计算几何
今天讲了计算几何,发几道水水的tyvj上的题解... 计算几何好难啊!@Mrs.General....怎么办.... 这几道题都是在省选之前做的,所以前面的Point运算啊,dcmp啊,什么什么的,基 ...
随机推荐
- javascript高级培训课程(一)
执行上下文 可执行代码类型-- 执行上下文类型 全局代码-- 全局上下文 函数代码-- 函数上下文 eval代码 -- eval上下文 arguments 超出传入参数个数的index 与形参不 ...
- iOS UIKit:viewController之Segues (4)
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- Jquery方法load之后导致js失效解决方法
Jquery方法load之后导致js失效解决方法 >>>>>>>>>>>>>>>>>>> ...
- Svg图片在asp网站上的使用
最近需要做一个动态的根据后台的返回数据而动态显示的导航图,然后我就采用了jquery+ajax+SVG矢量图来实现这个功能. 首先,客户给了个ai的矢量图,我对这一块不懂就找以前同事帮我转成了svg图 ...
- GitHub Desktop安装异常解决
为了更好的共同学习,共同进步,哥们推荐我使用GitHub记录自己每天的学习记录,当下很火的提供一个分布式的版本控制系统(Git)服务的网站,GitHub提供GitHub Desktop桌面程序方便协同 ...
- Java使用poi对Execl简单_写_操作
public class WriteExecl { @Test public void writeExeclTest() throws Exception{ OutputStream os = new ...
- (转)ecshop产品详情页显示不清晰
详情页面的商品图片的设置方法 后台商店设置-显示设置-显示设置(就是这里,商品图片宽度和高度设置的大点就行了,放大镜效果也清晰了) 按照您详情页面图片的实际显示大小来添写. 商品管理-图片批量处理,这 ...
- CAEmitterLayer
-(void)createFireworks{ CAEmitterLayer *fireworks = [CAEmitterLayer layer]; fireworks.emitterPositio ...
- 【原】ios tableViewCell 自适应高度
原文:http://www.cnblogs.com/A--G/p/4819051.html 前言:之前在做一个类似微博的小需求时候,用table view实现了微博文字和图片等等的基本展示,由于文字和 ...
- Relative与Absolute组合使用
小伙伴们学习了绝对定位的方法:使用position:absolute可以实现被设置元素相对于浏览器(body)设置定位以后, 大家有没有想过可不可以相对于其它元素进行定位呢?答案是肯定的,当然可以.使 ...