题意:

正方形四个边界上分别有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的更多相关文章

  1. POJ 1408 Fishnet【枚举+线段相交+叉积求面积】

    题目: http://poj.org/problem?id=1408 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  2. POJ 2402 Palindrome Numbers(LA 2889) 回文数

    POJ:http://poj.org/problem?id=2402 LA:https://icpcarchive.ecs.baylor.edu/index.php?option=com_online ...

  3. LA 4253 箭术(二分枚举)

    https://vjudge.net/problem/UVALive-4253 题意: 有n个平行于x轴的线段,每条线段代表一个靶子.判断是否可以站在x轴上[0,W]区间内的某个位置射箭. 思路:二分 ...

  4. LA 4794 状态DP+子集枚举

    状态压缩DP,把切割出的面积做状态压缩,统计出某状态下面积和. 设f(x,y,S)为在状态为S下在矩形x,y是否存在可能划分出S包含的面积.若S0是S的子集,对矩形x,y横切中竖切,对竖切若f(x,k ...

  5. LA 3695 部分枚举

    运用部分枚举的思想,很明显完全枚举点的思想是不可能的.改为枚举上下边界,当确定右边界j后,对左边界i,可以有点数为on[j]+on[i]+(leftu[j]-leftu[i])+leftd[j]-le ...

  6. LA 3887 - Slim Span 枚举+MST

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  7. LA 3602 - DNA Consensus String 枚举

    原题地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  8. LA 3602 DNA Consensus String (暴力枚举)

    题意:给定m个长度为n的DNA序列,求一个最短的DNA序列,使得总Hamming距离最小. Hamming距离等于字符不同的位置个数. 析:看到这个题,我的第一感觉是算时间复杂度,好小,没事,完全可以 ...

  9. LA 7049 Galaxy 枚举

    题意: \(x\)轴上有\(n\)个质量为\(1\)的点,他们的坐标分别为\(x_i\). 质心的坐标为\(\frac{\sum{x_i}} {n}\) 转动惯量为\(\sum{d_i^2}\),其中 ...

随机推荐

  1. Oracle 中 for update 和 for update nowait 的区别

    原文出处http://bijian1013.iteye.com/blog/1895412 一.for update 和 for update nowait 的区别 首先一点,如果只是select 的话 ...

  2. Android开发应用异步检查更新代码

    开发环境:android studio    sdk 4.0及以上 场景:用户点击检查更新按钮进行检查服务器版本号,若有新版本则进行下载更新.异步检测版本号 package com.example.q ...

  3. xubuntu install nodejs

    1.安装依赖sudo apt-get install g++ curl libssl-dev apache2-utils git-core 2.去官网获取最新版本 sudo wget http://n ...

  4. sed 详解

    sed 详解 1.简介 sed是非交互式的编辑器.它不会修改文件,除非使用shell重定向来保存结果.默认情况下,所有的输出行都被打印到屏幕上. sed编辑器逐行处理文件(或输入),并将结果发送到屏幕 ...

  5. CSDN——【低调的草原狼】——Ext4.2学习目录整理

    最近在研究ExtJS,发现CSDN中有个博客中一系列文档非常优秀,但是没有对目录进行整理,在此稍作整理,也为以后自己研究打下一个基础: 原文作者:低调的草原狼 目录:     1.ExtJS4.2学习 ...

  6. 【BZOJ】【1272】【BeiJingWC2008】Gate of Babylon

    组合数学+容斥原理 Orz zyf-zyf 多重集组合数0.0还带个数限制?  ——>  <组合数学>第6章  6.2带重复的组合 组合数还要模P 0.0? ——> Lucas ...

  7. C++编写Config类读取配置文件

    老外写的一段代码,在Server中编写这个类读取配置文件比较实用 //Config.h #pragma once #include <string> #include <map> ...

  8. 初识Redis

    package com.wangzhu.redis; import java.util.List; import org.junit.After; import org.junit.Before; i ...

  9. vlc/ffmepg/mplayer/gstreamer/openmax/mpc/ffdshow/directshow

    一些应该学习的开源框架与库用途和差别 一.播放器层次 这个层次上,是直接可以用的软件,已经做完了一切工作,如果我们需要用他们,是不需要写一行代码的,编译通过就可以拿来使用了,对于国内这些山寨公司来说, ...

  10. java socket知识点

    3.用线程池实现TCP服务器端时,首先创建一个ServerSocket实例,然后创建N个线程,每个线程反复循环,从(共享的)ServerSocket实例接收客户端连接.当多个线程同时调用一个Serve ...