LA 2402 (枚举) Fishnet
题意:
正方形四个边界上分别有n个点,将其划分为(n+1)2个四边形,求四边形面积的最大值。
分析:
因为n的规模很小,所以可以二重循环枚举求最大值。
求直线(a, 0) (b, 0) 和直线(0, c) (0, d)的交点,我是二元方程组求解得来的,然后再用叉积求面积即可。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm> const int maxn = + ;
struct HEHE
{
double a, b, c, d;
}hehe[maxn]; struct Point
{
double x, y;
Point(double x=, double y=):x(x), y(y) {}
};
typedef Point Vector; Vector operator - (const Vector& A, const Vector& B)
{ return Vector(A.x - B.x, A.y - B.y); } double Cross(const Vector& A, const Vector& B)
{ return (A.x*B.y - A.y*B.x); } Point GetIntersection(const double& a, const double& b, const double& c, const double& d)
{
double x = (a+(b-a)*c) / (-(b-a)*(d-c));
double y = (d-c)*x+c;
return Point(x, y);
} int main(void)
{
//freopen("2402in.txt", "r", stdin); int n;
while(scanf("%d", &n) == && n)
{
memset(hehe, , sizeof(hehe));
for(int i = ; i <= n; ++i) scanf("%lf", &hehe[i].a);
for(int i = ; i <= n; ++i) scanf("%lf", &hehe[i].b);
for(int i = ; i <= n; ++i) scanf("%lf", &hehe[i].c);
for(int i = ; i <= n; ++i) scanf("%lf", &hehe[i].d);
hehe[n+].a = hehe[n+].b = hehe[n+].c = hehe[n+].d = 1.0; double ans = 0.0;
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j)
{
Point A, B, C, D;
A = GetIntersection(hehe[i].a, hehe[i].b, hehe[j].c, hehe[j].d);
B = GetIntersection(hehe[i+].a, hehe[i+].b, hehe[j].c, hehe[j].d);
C = GetIntersection(hehe[i+].a, hehe[i+].b, hehe[j+].c, hehe[j+].d);
D = GetIntersection(hehe[i].a, hehe[i].b, hehe[j+].c, hehe[j+].d);
double temp = 0.0;
temp += Cross(B-A, C-A) / ;
temp += Cross(C-A, D-A) / ;
ans = std::max(ans, temp);
} printf("%.6f\n", ans);
} return ;
}
代码君
LA 2402 (枚举) Fishnet的更多相关文章
- POJ 1408 Fishnet【枚举+线段相交+叉积求面积】
题目: http://poj.org/problem?id=1408 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 2402 Palindrome Numbers(LA 2889) 回文数
POJ:http://poj.org/problem?id=2402 LA:https://icpcarchive.ecs.baylor.edu/index.php?option=com_online ...
- LA 4253 箭术(二分枚举)
https://vjudge.net/problem/UVALive-4253 题意: 有n个平行于x轴的线段,每条线段代表一个靶子.判断是否可以站在x轴上[0,W]区间内的某个位置射箭. 思路:二分 ...
- LA 4794 状态DP+子集枚举
状态压缩DP,把切割出的面积做状态压缩,统计出某状态下面积和. 设f(x,y,S)为在状态为S下在矩形x,y是否存在可能划分出S包含的面积.若S0是S的子集,对矩形x,y横切中竖切,对竖切若f(x,k ...
- LA 3695 部分枚举
运用部分枚举的思想,很明显完全枚举点的思想是不可能的.改为枚举上下边界,当确定右边界j后,对左边界i,可以有点数为on[j]+on[i]+(leftu[j]-leftu[i])+leftd[j]-le ...
- LA 3887 - Slim Span 枚举+MST
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- LA 3602 - DNA Consensus String 枚举
原题地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- LA 3602 DNA Consensus String (暴力枚举)
题意:给定m个长度为n的DNA序列,求一个最短的DNA序列,使得总Hamming距离最小. Hamming距离等于字符不同的位置个数. 析:看到这个题,我的第一感觉是算时间复杂度,好小,没事,完全可以 ...
- LA 7049 Galaxy 枚举
题意: \(x\)轴上有\(n\)个质量为\(1\)的点,他们的坐标分别为\(x_i\). 质心的坐标为\(\frac{\sum{x_i}} {n}\) 转动惯量为\(\sum{d_i^2}\),其中 ...
随机推荐
- Careercup - Facebook面试题 - 4892713614835712
2014-05-02 09:54 题目链接 原题: You have two numbers decomposed in binary representation, write a function ...
- libreoffice转换文档的方法(支持各平台各版本的libreoffice)
前段时间完成了一个利用libreoffice转换文档进行预览的资源管理系统,用的是jodconvert这个多年未更新的转换项目,由于版本不兼容等原因,导致最新版的libreoffice不能用,浪费了许 ...
- IIS Express start introduction and applicationHost modification
1. First you need create a web project in VS 2. When you finish your project, click start then IIS E ...
- ios 图形学习笔记
一.显示文本: 1.UIFont,用于设置显示的字体 初始化方法:fontNamesForFamilyName:(类方法) fontWithName:size:(类方法) 2.绘制文本的方法: NSS ...
- Introduction To Monte Carlo Methods
Introduction To Monte Carlo Methods I’m going to keep this tutorial light on math, because the goal ...
- MATLAB——axis
MATLAB——axis axis中文为“轴”之意,在matlab中用于控制坐标轴的范围和样式(颜色等). axis([XMIN XMAX YMIN YMAX]) 设置当前所绘图像的x轴和y轴的范围. ...
- Unity3d 一些 常见路径
Application.persistentDataPath C:\Users\Administrator\AppData\LocalLow\Company Name\Product Name 如果改 ...
- UVA 291 The House Of Santa Claus (DFS求一笔画)
题意:从左下方1开始,一笔画出圣诞老人的屋子(不过话说,圣诞老人的屋子是这样的吗?这算是个屋子么),输出所有可以的路径. 思路:贴代码. #include <iostream> #incl ...
- linux下获取时间差
#include <sys/time.h> struct timeval tpstart,tpend; float timeuse; gettimeofday(&t ...
- java基础知识回顾之java Thread类学习(十)--线程的状态以及转化使用的方法介绍
线程的概述: 线程是程序的多个执行路径,执行调度的单位,依托于进程存在.线程不仅可以共享进程的内存,而且还拥有一个属于自己的内存空间,这段内存空间叫做线程栈,是建立线程的时候由系 ...