POJ 1408 Fishnet【枚举+线段相交+叉积求面积】
题目:
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 1604 | Accepted: 1026 |
Description
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
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
Source
题意:
在直角坐标系中,把第一象限的那个单位面积的正方形分成 n*n 个小四边形,
求最大四边形面积
注意:
点的输入顺序【周边上点,都是按照从小到大的顺序输入的】
算法: 枚举+线段求交点+叉积求面积
思路:
存储每一个点【周边的+线段交点】,
然后依次遍历每一个四边形的面积
Code:
/****************************************************************************
C Accepted 208 KB 16 ms C++ 2155 B
题意:
在直角坐标系中,把第一象限的那个单位面积的正方形分成 n*n 个小四边形,
求最大四边形面积 注意:点的输入顺序【周边上点,都是按照从小到大的顺序输入的】 算法:枚举+线段求交点+叉积求面积 思路:存储每一个点【周边的+交点】,
然后依次遍历每一个四边形的面积
******************************************************************************/
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std; const int maxn = 40;
struct Point{
double x,y;
Point() {}
Point(double _x, double _y){
x = _x;
y = _y;
} Point operator + (const Point &B) const {
return Point(x+B.x, y+B.y);
}
Point operator - (const Point &B) const {
return Point(x-B.x, y-B.y);
}
Point operator * (const double &p) const {
return Point(p*x, p*y);
} }p[maxn][maxn];
typedef Point Vector; /** 叉积求面积 */
double Cross(Point A, Point B)
{
return A.x*B.y - A.y*B.x;
} /** 求线段交点 */
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 Area(Point a, Point b, Point c, Point d){
return fabs(Cross(c-a,b-a)) / 2.0 + fabs(Cross(c-a,d-a)) / 2.0;
} int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
if(n == 0) break; p[0][0] = Point(0,1); //定位四个顶点
p[0][n+1] = Point(1,1);
p[n+1][0] = Point(0,0);
p[n+1][n+1] = Point(1,0); double a,b,c,d; //依次存储周边的点
for(int i = 1; i <= n; i++) //a
{
scanf("%lf", &a);
p[n+1][i] = Point(a,0);
} for(int i = 1; i <= n; i++)// b
{
scanf("%lf", &b);
p[0][i] = Point(b,1);
} for(int i = n; i >= 1; i--) //c
{
scanf("%lf", &c);
p[i][0] = Point(0,c);
} for(int i = n; i >= 1; i--) //d
{
scanf("%lf", &d);
p[i][n+1] = Point(1,d);
} //求中间的交点
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
p[i][j] = GetLineIntersection(p[i][0], p[i][0]-p[i][n+1], p[n+1][j], p[n+1][j]-p[0][j]);
}
} double ans = 0;
double tmp;
//从上到下、从左到右依次遍历每个四边形
for(int i = 0; i <= n; i++)
{
for(int j = 0; j <= n; j++)
{
tmp = Area(p[i][j],p[i][j+1],p[i+1][j+1],p[i+1][j]);
ans = max(ans,tmp);
}
}
printf("%.6lf\n", ans);
}
return 0;
}
POJ 1408 Fishnet【枚举+线段相交+叉积求面积】的更多相关文章
- POJ 1039 Pipe 枚举线段相交
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9493 Accepted: 2877 Description ...
- 两条线段求交点+叉积求面积 poj 1408
题目链接:https://vjudge.net/problem/POJ-1408 题目是叫我们求出所有四边形里最大的那个的面积. 思路:因为这里只给了我们正方形四条边上的点,所以我们要先计算横竖线段两 ...
- poj 1066(枚举+线段相交)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6328 Accepted: 2627 Des ...
- POJ 1066 Treasure Hunt(线段相交判断)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4797 Accepted: 1998 Des ...
- poj 3304(直线与线段相交)
传送门:Segments 题意:线段在一个直线上的摄影相交 求求是否存在一条直线,使所有线段到这条直线的投影至少有一个交点 分析:可以在共同投影处作原直线的垂线,则该垂线与所有线段都相交<==& ...
- POJ 1066--Treasure Hunt(判断线段相交)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7857 Accepted: 3247 Des ...
- POJ 1039 直线和线段相交
题意: 题意很好理解,从左边射过来的光线,最远能经过管道到右边多少距离. 分析: 光线一定经过一个上端点和一个下端点,这一点很容易想到.然后枚举上下端点即可 #include <iostream ...
- POJ 2653 Pick-up sticks(线段相交)
题意:给定n个木棍依次放下,要求最终判断没被覆盖的木棍是哪些. 思路:快速排斥以及跨立实验可以判断线段相交. #include<algorithm> #include<cstdio& ...
- [poj 1127]Jack Straws[线段相交][并查集]
题意: 给出一系列线段,判断某两个线段是否连通. 思路: 根据线段相交情况建立并查集, 在同一并查集中则连通. (第一反应是强连通分量...实际上只要判断共存即可, 具体的方向啊是没有关系的..) 并 ...
随机推荐
- js bind 绑定this指向
1.示例代码 <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UT ...
- Android开发之Is Library篇
一.生活场景描述 由于公司有一个项目开发的时间比较长,项目里堆砌的代码也比较多,并且有些功能在给不同客户发布的时候有些功能还不需要,这样功能模块分离就很有必要了. 所以,Library就被推到了前台, ...
- Java: 获取当前执行位置的文件名/类名/方法名/行号
在 JAVA 程序有时需要获取当前代码位置, 于是就利用 Thread.currentThread().getStackTrace() 写了下面这个工具类, 用来获取当前执行位置处代码的文件名/类名/ ...
- jQuery控制form表单元素聚焦
CreateTime--2017年5月28日08:57:16Author:Marydon jQuery使form表单的第一个文本框聚焦 /** * 使form表单的第一个文本框聚焦 */ func ...
- linux下使用tc(Traffic Control) 流量控制命令模拟网络延迟和丢包
目录 TC案例 TC常用命令 TC安装 TC原理介绍 TC规则 TC操作原理 TC命名规则 TC单位 TC命令 TC案例 如何使用tc模拟网络延迟和丢包 修改网络延时: sudo tc qdisc ...
- dos2unix dos文本转换为linux文本 /bin/bas^M:bad interpreter
第一种方法:dos2unix -f 文本名 第二种方法: 首先:vi 文本名 然后::set ff? 如果出现fileforma=dos那么就确定是linux和windows之间的不完全兼容 :set ...
- (初学者)安装hadoop集群注意事项
1.关闭防火墙 2.所有的hadoop操作都是hadoop用户下面的,同时需要用hadoop用户登录之后,对于其他的机器的hadoop用户可以免密登录 3.hadoop用户在root组下面,不是附加组 ...
- linux mount-umount命令常用记录
每次挂在u盘都忘记,这次记录下. umount命令: 必杀:umount -l /dev/sda1 (有时候卸载不能卸,加-l(不是1,是小写字母l)参数,表示在设备不忙时卸载设备,就可成功卸载设备) ...
- 2017-5-14 湘潭市赛 Similar Subsequence 分析+四维dp+一些简单优化
Similar Subsequence Accepted : Submit : Time Limit : MS Memory Limit : KB Similar Subsequence For gi ...
- Spark Core源代码分析: RDD基础
RDD RDD初始參数:上下文和一组依赖 abstract class RDD[T: ClassTag]( @transient private var sc: SparkContext, @tran ...