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 ...
随机推荐
- Oracle 学习路径
学习路线图: 学习的方法和思路: 有了google为什么还需要学习? 有了官方文档还需要学习了吗? 工作角色: 开发人员:SQL操作数据库,PL/SQL实现逻辑结构.企业需要最多.对逻辑思维要求比较高 ...
- Andriod wifi 基本操作
从用户角度看,Android Wi-Fi模块自下向上可以看为5层:硬件驱动程序,wpa_suppplicant,JNI,WiFi API,WifiSettings应用程序. 1.wpa_supplic ...
- matlab实现复合梯形法则
复合梯形法则: function int_f = CompoundEchelon( f, a, b, m ) % input : f : function handler % a : the lowe ...
- iOS常见问题(3)
一.发现不少人在给成员变量初始化的时候,容易进错一个方法去初始化. //注意这个方法只有在内存发生警告的时候才会调用. - (void)didReceiveMemoryWarning { [super ...
- COCOS2DX2.2.2 创建CCEditBox输入框架实现文本及密码输入
本文转载于: http://5.quanpao.com/?p=561 使用CCEditBox需要启用扩展库既extension ,因此需要引入这个空间名 有两种方法, using namespace ...
- openstack安装、卸载与启动
一.安装: 更新: sudo apt-get update sudo apt-get upgrade 安装图形化界面: sudo apt-get install ubuntu-desktop 安装gc ...
- ListView防止滑动变色的小技巧
listview滑动时会变成白色,如果背景色不是白色的话可以通过设置setCacheColorHint(Color.TRANSPARENT);来避免变色,.对应的xml也可以进行设置.
- Linux命令zip和unzip
问题描述: 使用Linux中命令zip和unzip 问题解决: 命令名: zip 功能说明:压缩文件. 语 法:zip [-AcdDfFghjJKlLmoqrSTuvVwXyz$][- ...
- 引擎设计跟踪(九.10) Max插件更新,地形问题备忘
最近没有大的更新. 最近本来要做max的骨骼/动画导出, 看导出插件代码的时候, 突然想起之前tagent space导出的疑问, 于是确认了一下. http://www.cnblogs.com/cr ...
- 【MongoDb--初入江湖】windows下安装MongoDb
一.windows下安装MongoDb http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/