题意:第一象限里有一个角,把n(n <= 10)个给定边长的正方形摆在这个角里(角度任意),使得阴影部分面积尽量大。

分析:当n个正方形的对角线在一条直线上时,阴影部分面积最大。

1、通过给定的xa,ya,xb,yb,可求k1,k2。

2、当n个正方形的对角线在一条直线上时,设A(x1,k1*x1),B(x2,k2*x2),

可列方程组:

解得

3、利用叉积算出AOB的面积,再减去正方形面积和的一半。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b) {
if(fabs(a - b) < eps) return 0;
return a < b ? -1 : 1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
struct Point{
double x, y;
void set(double xx, double yy){
x = xx;
y = yy;
}
};
double getArea(Point &A, Point &B){
return A.x * B.y - A.y * B.x;
}
int main(){
int N;
while(scanf("%d", &N) == 1){
if(!N) return 0;
Point A, B;
scanf("%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y);
double L = 0;
double area = 0;
for(int i = 0; i < N; ++i){
double l;
scanf("%lf", &l);
L += l;
area += l * l / 2;
}
double k1 = A.y / A.x;
double k2 = B.y / B.x;
if(k1 > k2){
swap(k1, k2);
}
double x1 = (k2 + 1) * L / (k2 - k1);
double y1 = k1 * x1;
double x2 = (k1 + 1) * L / (k2 - k1);
double y2 = k2 * x2;
A.set(x1, y1);
B.set(x2, y2);
double ans = getArea(A, B) / 2 - area;
printf("%.3lf\n", ans);
}
return 0;
}

  

最新文章

  1. OC编码问题输出中文
  2. PHP5: mysqli 插入, 查询, 更新和删除 Insert Update Delete Using mysqli (CRUD)
  3. 【OpenCV入门教程之一】 安装OpenCV:OpenCV 3.0 +VS 2013 开发环境配置
  4. 研究实验1_搭建一个精简的C语言开发环境(包含部分经典的前言)
  5. CSharp Similarities and Differences
  6. javascript实现数据结构:广义表
  7. OpenCV249 for python278 最简配置方案
  8. C++ 11 学习2:空指针(nullptr) 和 基于范围的for循环(Range-based for loops)
  9. .NET 跨平台界面框架和为什么你首先要考虑再三
  10. Flex 基础语法(一)
  11. leetcode刷题第一日&lt;两数和问题&gt;
  12. shogun docker image 中import shogun error
  13. VMWare安装CentOS 6.5图解
  14. Python导入jar包
  15. Django集成Markdown编辑器【附源码】
  16. ssh架构之hibernate(一)简单使用hibernate完成CRUD
  17. django_models后台管理myarya
  18. MapReduce的Shuffle过程介绍
  19. python 多线程 示例
  20. [Angular] Angular Attribute Decorator - When to use it?

热门文章

  1. 《Redis深度历险:核心原理和应用实践》千帆竞发——分布式锁
  2. wyh的dp入门刷题笔记
  3. java Spring整合Freemarker的详细步骤
  4. WebRobot1.8.2网站多功能网络安全渗透检测工具
  5. 前端学习(20)~css布局(十三)
  6. CentOS 7 搭建本地YUM仓库,并定期同步阿里云源
  7. Linux分发版本的试用及选择工具
  8. Day4 - G - 确定比赛名次 HDU - 1285
  9. Spark Deploy 模块
  10. eclipse、idea中自动生成元模型JPA元模型对象