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}\),其中 ...
随机推荐
- 【转】 Android经验: proguard 阻碍 webview 正常工作
转自:http://blog.csdn.net/span76/article/details/9065941 WebView 常识 使用 Alert 提供消息 我在页面经常用 Alert 提供消息, ...
- ADT 怎么删除logcat过滤规则
刚才新增了一个过滤规则,但是没有找到在哪里删除,也看不到全部的log输出, 解决方案如下:
- P1676陶陶吃苹果 - vijos
描述 curimit知道陶陶很喜欢吃苹果.于是curimit准备在陶陶生日的时候送给他一棵苹果树. curimit准备了一棵这样的苹果树作为生日礼物:这棵苹果树有n个节点,每个节点上有c[i]个苹果, ...
- Unix守护进程
问题描述: Unix守护进程 问题解决: Unix守护进程没有控制终端,终端名设置为问号(?),终端前台进程组ID设置(TPGID)为-1 守护进程编写规则: (1) ...
- CKFinder 1.4.3 任意文件上传漏洞
CKFinder 是国外一款非常流行的所见即所得文字编辑器,其1.4.3 asp.net版本存在任意文件上传漏洞,攻击者可以利用该漏洞上传任意文件. CKFinder在上传文件的时候,强制将文件名(不 ...
- PHP防止SQL注入与几种正则表达式讲解
注入漏洞代码和分析 代码如下: <?php function customerror($errno, $errstr, $errfile, $errline) { echo <b& ...
- SNAT
http://blog.chinaunix.net/uid-2628744-id-2454879.html
- Thread的第三天学习
线程互斥 public void method1() { synchronized(this) { ... } } 等同于 public synchronized void method1() { ...
- java.util.concurrent包API学习笔记
newFixedThreadPool 创建一个固定大小的线程池. shutdown():用于关闭启动线程,如果不调用该语句,jvm不会关闭. awaitTermination():用于等待子线程结束, ...
- 李洪强iOS开发之OC[017]函数和方法的区别
// // main.m // 15 - 函数和对象的方法的区别 // // Created by vic fan on 16/7/12. // Copyright © 2016年 李洪强. ...