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啊,什么什么的,基 ...
随机推荐
- c#中jeson字符串和OBJECT对象的相互转换
对于本问题 我用三步来分别说明实现过程 1.定义一个类---- 实现转换的具体方法 using System; using System.Collections.Generic; using Sy ...
- Linux sed命令常用方法
sed也成stream editor,流编辑器,是Linux上常用的文本处理工具. 通用格式:sed 行范围 模式/RegExp/ 文件 模式: d 删除 p 打印符合条件的行 a \strin ...
- Oracle修改被占用的临时表结构
这两天在修改临时表的类型时,提示”attempt to create,alter or drop an index on temporary table already in use“的错误,由于临时 ...
- gamit10.6问题汇总
1.在处理精密星历时,提示:old version of file not supported (name svnav.dat) 解决办法:在gamit10.5中不会出现这个问题,10.6中的官方文档 ...
- Python之路【第十七篇】:Django之【进阶篇】
Python之路[第十七篇]:Django[进阶篇 ] Model 到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞: 创建数据库,设计表结构和字段 使用 MySQLdb 来连接 ...
- 用CSS+Jquery实现一个漂浮的窗体
一.项目需求: 实现一个用于网站主页面 从窗体左上角开始飘到右下角 之后又飘到右上角 十秒之后消失的效果. 二.需求分析: 首先 应当想要漂浮的内容放在一个容器内,也就是一个DIV,设计它的样式,不管 ...
- RegistryKey 类
表示 Windows 注册表中的项级节点. 此类是注册表封装. 继承层次结构 System.Object System.MarshalByRefObject Microsoft.Win32. ...
- Android 控件 之 Menu 菜单
http://www.cnblogs.com/Mrs-cc/archive/2012/07/21/2603042.html 1.OptionsMenu (选项菜单)用法总结 使用方法: 方法一:添 ...
- centos6.5安装vsftp服务并配置虚拟账户ftp
当我们的用户量越来越大时,继续创建更多的系统用户是不明智的,这时就需要为vsftpd创建虚拟账户,但vsftpd虚拟账户的数据库要保存在Berkeley DB格式的数据文件中,所以需要安装db4- ...
- 获取IP城市
新浪的接口 : http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 多地域测试方法:http://int.dpool.sina. ...