B - Football Goal

Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

Unlike most students of the Mathematical Department, Sonya is fond of not only programming but also sports. One fine day she went to play football with her friends. Unfortunately, there was no football field anywhere around.
There only was a lonely birch tree in a corner of the yard. Sonya searched the closet at her home, found two sticks, and decided to construct a football goal using the sticks and the tree. Of course, the birch would be one of the side posts of the goal. It
only remained to make the other post and the crossbar.
Sonya wanted to score as many goals as possible, so she decided to construct a goal of maximum area. She knew that the standard football goal was rectangular, but, being creative, she assumed that her goal could have the form
of an arbitrary quadrangle.
You can assume that the birch tree is a segment of a straight line orthogonal to the ground.

Input

The only line contains integers a and b, which are the lengths of the sticks (1 ≤ ab ≤ 10 000). It is known that the total length of the sticks is less than the height of the birch tree.

Output

Output the maximum area of the goal that can be constructed with the use of the sticks and the birch tree. The answer must be accurate to at least six fractional digits.

Sample Input

input output
2 2
4.828427125

|

|

|

|__________________               找两个杆子来围住左边这个 使得面积最大;

初始想法是枚举角度;尽管精度感觉都对了但是还是WA

错误的代码:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;
#define PI acos(-1.0)
#define SET(a,b) memset(a,b,sizeof(a))
#define DE(x) cout<<#x<<"="<<x<<endl //308.812191
int main(){
double x,y;
double sum=0;
while(~scanf("%lf%lf",&x,&y)){
sum=x*y;
double now;
double p=PI/2000.0;
// double p2=p1;
for(int i=1;i<=2000;i++){
double x1=x*sin(i*p);
double x2=x*cos(i*p);
for(int j=1;j<=2000-i;j++){
double y1=y*sin(j*p);
double y2=y*cos(j*p);
now=x1*x2/2.0+y1*y2/2.0+x2*y2;
if(now>sum)sum=now;
}
}
printf("%.6lf",sum);
}
return 0;
}

后面

 利用2*ac*bc<=ac^2+bc^2=ab^2    三角形abd可以利用海伦公式,三角形abc=1/2 ac*cb 最大就是ab^2/4

然后三分 0到x+y 就出来了

三分的模板:

double solve()
{
double Left, Right;
double mid, midmid;
double mid_value, midmid_value;
Left = 0; Right = x+y;
while (Left + eps <= Right)
{
mid = (Left + Right) / 2.0;
midmid = (mid + Right) / 2.0;
mid_value=getsum(mid,x,y);
midmid_value=getsum(midmid,x,y);
if (mid_value>=midmid_value) Right = midmid;
else Left = mid;
}
return mid_value;
}
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#define eps 1e-9
using namespace std; //308.812191
double getsum(double c,double a,double b){
double p=(a+b+c)/2.0;
return c*c/4.0+sqrt(p*(p-a)*(p-b)*(p-c));
}
double x,y;
double solve()
{
double Left, Right;
double mid, midmid;
double mid_value, midmid_value;
Left = 0; Right = x+y;
while (Left + eps <= Right)
{
mid = (Left + Right) / 2.0;
midmid = (mid + Right) / 2.0;
mid_value=getsum(mid,x,y);
midmid_value=getsum(midmid,x,y);
if (mid_value>=midmid_value) Right = midmid;
else Left = mid;
}
return mid_value;
}
int main(){ while(~scanf("%lf%lf",&x,&y)){ printf("%.9lf\n",solve());
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

三分--Football Goal(面积最大)的更多相关文章

  1. ural 1874 Football Goal

    #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> u ...

  2. 【BZOJ1069】【SCOI2007】最大土地面积

    题目大意:给定有n个点的点集,求该点集中任意四个点所构成的四边形中面积最大四边形的面积. 我们不难想到(不难yy出来),面积最大的四边形的四个顶点一定所给定的点集所构成的凸包上.我们求出给定点集的集合 ...

  3. POJ 3301 Texas Trip (三分)

    题目链接 题意 : 给你若干个点,让你找最小的正方形覆盖这所有的点.输出面积. 思路 : 三分枚举正方形两对边的距离,然后求出最大,本题用的是旋转正方形,也可以用旋转点,即点的相对位置不变. 正方形从 ...

  4. [三分]HDOJ 5531 Rebuild

    题意:给n个点,以这n个点为圆心画圆,使得所有的圆与其相邻的圆相切. 求n个圆最小的面积和. 分析:很容易想到确定了其中一个圆的半径之后,其他的圆的半径也能随之确定了. 画一画三个点的和四个点的,会发 ...

  5. UVA 10194 Football (aka Soccer)

     Problem A: Football (aka Soccer)  The Problem Football the most popular sport in the world (america ...

  6. HDU-1225 Football Score

    http://acm.hdu.edu.cn/showproblem.php?pid=1225 一道超级简单的题,就因为我忘记写return,就wa好久,拜托我自己细心一点. 学习的地方:不过怎么查找字 ...

  7. HDU_2036——多边形面积,行列式计算

    Problem Description “ 改革春风吹满地, 不会AC没关系; 实在不行回老家, 还有一亩三分地. 谢谢!(乐队奏乐)”话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也 ...

  8. poj3301 三分

    Texas Trip Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4998   Accepted: 1559 Descri ...

  9. n多边形面积

    “ 改革春风吹满地,不会AC没关系;实在不行回老家,还有一亩三分地.谢谢!(乐队奏乐)” 话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是云里雾里,而且,还竟然来这么几句打油诗.好呀 ...

随机推荐

  1. EXT格式误删除恢复

    http://hatemysql.com/ 1.从/proc文件系统恢复数据#lsof |grep -i deletecat 11791 root 1w REG 253,0 94 1048589 /h ...

  2. asp.net中分页与存储过程的一些总结

    一.接上文,使用的是jquery AJAX 进行分页 分页存储过程代码如下: ALTER PROCEDURE [dbo].[USP_GetAlbumByPage] @pageIndex int,--当 ...

  3. [leetcode]_Climbing Stairs

    我敢保证这道题是在今早蹲厕所的时候突然冒出的解法.第一次接触DP题,我好伟大啊啊啊~ 题目:一个N阶的梯子,一次能够走1步或者2步,问有多少种走法. 解法:原始DP问题. 思路: 1.if N == ...

  4. Windows下安装Elasticsearch

    1.下载elasticsearch-1.6.0 .jdk-7u67-windows-x64.exe 1.6.0必须用jdk1.7才能运行 2.配置JAVA_HOME:C:\Program Files\ ...

  5. Lua 练习中的Bug 以及日志

    使用 Lua 中的table.getn获得数组的table的长度:运行失败-- > t ={1,2,3 } > print(table.getn(t)) stdin:1: attempt ...

  6. 第十六章 调试及安全性(In .net4.5) 之 调试程序

    1. 概述 本章内容包括 如何选择合适的构建类型.创建和管理编译指令.管理程序数据文件(pdb)和指令. 2. 主要内容 2.1 构建类型 .net中默认的两种生成模式是 发布(Release)模式 ...

  7. python 面向对象、特殊方法与多范式、对象的属性及与其他语言的差异

    1.python 面向对象 文章内容摘自:http://www.cnblogs.com/vamei/archive/2012/06/02/2532018.html   1.__init__() 创建对 ...

  8. MongoDB 学习笔记(二)—— MongoDB Shell

    MongoDB自带一个JavaScript shell 可以从命令行中与MongoDB交互,功能非常强大.如在上一节最后一张图所看到,可以执行JavaScript程序. 运行Shell 前提是启动Mo ...

  9. Collection、Iterator、Set、HashSet

    Collection接口的基本方法 boolean add(Object o) 向集合当中加入一个对象 void clear() 删除集合当中的所有对象 boolean isEmpty() 判断集合是 ...

  10. 界面控件 - 滚动条ScrollBar

    界面是人机交互的门户,对产品至关重要.在界面开发中只有想不到没有做不到的,有好的想法,当然要尝试着做出来.对滚动条的扩展,现在有很多类是的例子. VS2015的代码编辑是非常强大的,其中有一个功能可以 ...