UVa 1301 - Fishnet
求出所有交点枚举每个四边形找最大面积即可。
#include <cstdio>
#include <cmath>
#include <algorithm> using namespace std; const int MAXN = ; const double eps = 1e-; struct Point
{
double x, y;
Point( double x = , double y = ):x(x), y(y) { }
}; typedef Point Vector; 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 );
} Vector operator/( Vector A, double p ) //向量数除
{
return Vector( A.x / p, A.y / p );
} bool operator<( const Point& A, const Point& B ) //两点比较
{
return A.x < B.x || ( A.x == B.x && A.y < B.y );
} int dcmp( double x ) //控制精度
{
if ( fabs(x) < eps ) return ;
else return x < ? - : ;
} double Dot( Vector A, Vector B ) //向量点乘
{
return A.x * B.x + A.y * B.y;
} double Length( Vector A ) //向量模
{
return sqrt( Dot( A, A ) );
} double Angle( Vector A, Vector B ) //向量夹角
{
return acos( Dot(A, B) / Length(A) / Length(B) );
} double Cross( Vector A, Vector B ) //向量叉积
{
return A.x * B.y - A.y * B.x;
} double Area2( Point A, Point B, Point C ) //向量有向面积
{
return Cross( B - A, C - A );
} Vector Rotate( Vector A, double rad ) //向量旋转
{
return Vector( A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad) );
} 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;
} bool SegmentProperIntersection( Point a1, Point a2, Point b1, Point b2 ) //线段相交,交点不在端点
{
double c1 = Cross( a2 - a1, b1 - a1 ), c2 = Cross( a2 - a1, b2 - a1 ),
c3 = Cross( b2 - b1, a1 - b1 ), c4 = Cross( b2 - b1, a2 - b1 );
return dcmp(c1)*dcmp(c2) < && dcmp(c3) * dcmp(c4) < ;
} bool OnSegment( Point p, Point a1, Point a2 ) //点在线段上,不包含端点
{
return dcmp( Cross(a1 - p, a2 - p) ) == && dcmp( Dot( a1 - p, a2 - p ) ) < ;
} Point P[][MAXN];
Point ch[MAXN][MAXN]; void init( int n )
{
ch[][].x = 0.0, ch[][].y = 0.0;
ch[][n + ].x = 1.0, ch[][n + ].y = 0.0;
ch[n + ][].x = 0.0, ch[n + ][].y = 1.0;
ch[n + ][n + ].x = 1.0, ch[n + ][n + ].y = 1.0; for ( int i = ; i <= n; ++i )
ch[][i] = P[][i];
for ( int i = ; i <= n; ++i )
ch[n + ][i] = P[][i];
for ( int i = ; i <= n; ++i )
ch[i][] = P[][i];
for ( int i = ; i <= n; ++i )
ch[i][n + ] = P[][i]; for ( int i = ; i <= n; ++i )
for ( int j = ; j <= n; ++j )
ch[i][j] = GetLineIntersection( P[][i], P[][i] - P[][i], P[][j], P[][j] - P[][j] ); return;
} int main()
{
int n;
while ( scanf( "%d", &n ), n )
{
for ( int i = ; i < ; ++i )
{
for ( int j = ; j <= n; ++j )
{
double a;
scanf( "%lf", &a );
switch( i )
{
case :
P[i][j].x = a;
P[i][j].y = 0.0;
break;
case :
P[i][j].x = a;
P[i][j].y = 1.0;
break;
case :
P[i][j].x = 0.0;
P[i][j].y = a;
break;
case :
P[i][j].x = 1.0;
P[i][j].y = a;
break;
}
}
} init( n ); double ans = 0.0;
for ( int i = ; i <= n; ++i )
for ( int j = ; j <= n; ++j )
{
Point a = ch[i][j], b = ch[i][j + ], c = ch[i + ][j + ], d = ch[i + ][j];
double area = fabs( Cross( b-a, c-a )/2.0 ) + fabs( Cross( c-a, d-a )/2.0 );
if ( area > ans ) ans = area;
} printf( "%.6f\n", ans ); }
return ;
}
UVa 1301 - Fishnet的更多相关文章
- uva 1354 Mobile Computing ——yhx
		
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
 - UVA 10564 Paths through the Hourglass[DP 打印]
		
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
 - UVA 11404 Palindromic Subsequence[DP LCS 打印]
		
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
 - UVA&&POJ离散概率与数学期望入门练习[4]
		
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
 - UVA计数方法练习[3]
		
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
 - UVA数学入门训练Round1[6]
		
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
 - UVA - 1625 Color Length[序列DP 代价计算技巧]
		
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
 - UVA - 10375 Choose and divide[唯一分解定理]
		
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
 - UVA - 11584 Partitioning by Palindromes[序列DP]
		
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...
 
随机推荐
- 命令行参数的处理函数getopt
			
命令参数 在linux下, shell命令的参数分两种情况: a.参数需要附加信息, 如"wget http://www.abc.com/1.zip -o 1.zip" b.参数不 ...
 - snmptrap使用
			
SNMP简单网络管理协议,其中其支持的一个命令snmptrap命令,用于模拟向管理机发送trap消息. 启动陷阱方法: snmptrapd -C -c /etc/snmp/snmptrapd.co ...
 - 阿里云mysql数据库恢复总结,mysql binlog日志解析
			
由于意外..阿里云mysql中有一张表被全部删除了,深吸三口气候,开始解决. 首先用凌晨的自动备份的,进行全量恢复,然后找binlog日志(见下文),查找从全量备份到数据删除之间的记录 这导致了一个问 ...
 - C# type - IsPrimitive
			
Type t = typeof(string); if (t.IsPrimitive)//not { Console.WriteLine("string is a Primitive&quo ...
 - dbutils 执行sql返回的数据类型
			
//ArrayHandler: 把结果集中的第一行数据转成对象数组 //ArrayListHandler:把结果集中的每一行数据都转成一个对象数组,再存放到List中 //BeanHandler:将结 ...
 - 得到当前活动的controller
			
UIWindow+PazLabs.h (header file) #import <UIKit/UIKit.h> @interface UIWindow (PazLabs) - (UIVi ...
 - 用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。
			
// test14.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...
 - oracle——分析函数——排序值分析函数
			
一.问题描述 查询列表时,我们有时需要对查询结果依据某个字段进行排名. 如果每条记录在排序字段上都不相同,我们可以将原查询作为一个视图,查询其rownum,便可以实现简单排序,例如: select r ...
 - [CF]codeforces round#366(div2)滚粗记
			
开场心理活动:啊打完这场大概有1700了吧 中途心理活动:啊这个ABC看起来都随便做啊 死亡原因:欸怎么没网了 -75 .. A [题意]Hulk说完一句I hate会说that I love 然后是 ...
 - 在线最优化求解(Online Optimization)之一:预备篇
			
在线最优化求解(Online Optimization)之一:预备篇 动机与目的 在实际工作中,无论是工程师.项目经理.产品同学都会经常讨论一类话题:“从线上对比的效果来看,某某特征或因素对xx产品的 ...