题意:

正方形四个边界上分别有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 ;
}

代码君

最新文章

  1. codevs 1002 搭桥
  2. Netty5.x中新增和值得注意的点
  3. 文字处理TX Text Control X10独家揭秘(二):图像占位符合并
  4. C#入门篇6-7:字符串操作 看看字符串的特殊之处 值类型与引用类型的区别
  5. Http状态码301和302概念简单区别
  6. Failed to load libGL.so in android
  7. 正则转nfa:完成
  8. 让UIScrollView、UITableView的滚动条一直显示
  9. 多线程监控文件夹,FlieSystemWatcher,并使用共享函数
  10. 解决Ubuntu Server 12.04换了网卡MAC地址后 网络不可用的问题.
  11. 关于NGINX下开启PHP-FPM 输出PHP错误日志的设置(已解决)
  12. Yet Another Multiple Problem(bfs好题)
  13. 手机自动化测试:appium源码分析之bootstrap十六
  14. ReactiveObjC使用
  15. PHP 简单的加密解密方法
  16. mysql之数据库添加索引优化查询效率
  17. laravel 定义翻译字符串
  18. Python基础之面向对象思维解决游戏《天龙八部》
  19. 超小Web手势库AlloyFinger原理(转载)
  20. call apply bind的区别

热门文章

  1. adb 选择设备
  2. IntelliJ IDEA的Maven项目在修改时报java.lang.OutOfMemoryError: PermGen space异常
  3. 编写一段程序,从标准输入读取string对象的序列直到连续出现两个相同的单词或者所有单词都读完为止。使用while循环一次读取一个单词,当一个单词连续出现两次是使用break语句终止循环。输出连续重复出现的单词,或者输出一个消息说明没有人任何单词是重复出现的。
  4. 【转载】C++中结构体的声明和定义
  5. Unity3d集成移动MM SDK 2.2的技术要点(坑爹的MM SDK)
  6. 【leetcode】Combination Sum (middle)
  7. Git 使用方法
  8. hdu 1329 Hanoi Tower Troubles Again!
  9. Android 使用MediaRecorder录音
  10. [转]Ubuntu alternate和desktop区别