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. Apache 多端口多站点配置实例

    分享下Apache多端口多站点的配置方法,配置apache服务器的朋友参考下. 配置httpd.conf 监听多个端口 复制代码代码如下: # Listen: Allows you to bind A ...

  2. mac虚拟机parallels 无法启动 "Windows 7" 虚拟机

    关机前在虚拟机上安装了个游戏有点大,第二天开机就使用不了虚拟机了: 提示:mac虚拟机parallels  无法启动 "Windows 7" 虚拟机.  释放至少 241 MB 的 ...

  3. Spark官方文档——本地编写并运行scala程序

    快速开始 本文将介绍如何用scala.java.python编写一个spark单击模式的程序. 首先你只需要在一台机器上成功建造Spark:做法: 进入Spark的根目录,输入命令:$ sbt/sbt ...

  4. PHP 简单实现MySQL数据搜索、添加数据功能 以设备管理为例

    测试截图: 数据库bzec ,表shebeidangan 列sb_name,sb_numandtype,sb_home,sb_usedate,sb_address,sb_updatetime,sb_r ...

  5. .NET Framework4.0 下的多线程

    一.简介 在4.0之前,多线程只能用Thread或者ThreadPool,而4.0下提供了功能强大的Task处理方式,这样免去了程序员自己维护线程池,而且可以申请取消线程等...所以本文主要描述Tas ...

  6. Noise,Error,wighted pocket Algorithm

    错误衡量(Error Measure) 有两种错误计算方法: 第一种叫0/1错误,只要[预测≠目标]则认为犯错,通常用于分类:通常选择,错误比较大的值作为y˜的值 第二种叫平方错误,它衡量[预测与目标 ...

  7. JLink V8初始化exynos4412脚本

    /** ****************************************************************************** * @author    Maox ...

  8. try-catch-finally中return语句的执行

    catch里return后还会执行finally吗??在java里,是的.但是值得注意的是,在存在try-catch-finally的方法中,return可能出现的位置有4个,在try中,在catch ...

  9. SQLServer异常捕获

    在SQLserver数据库中,如果有很多存储过程的时候,我们会使用动态SQL进行存储过程调用存储过程,这时候,很可能在某个环节就出错了,但是出错了我们很难去跟踪到出错的存储过程,此时我们就可以使用异常 ...

  10. Concurrency Series 1

    Difference between Processes and Threads Processes A process has a self-contained execution environm ...