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. Windows Server 2003搭建FTP服务器 实现盘符之间切换

     Serv-U中设置虚拟目录的方法 如果在E盘下有一个名为LoveHina的目录,在F盘下也有一个名为LoveHina的目录.那么,如何让使用同一个账号的用户可以同时访问这两个目录呢? 我们可以使用S ...

  2. C#解析JSON字符串总结

    JSON文件读取到内存中就是字符串,.NET操作JSON就是生成与解析JSON字符串. 操作JSON通常有以下几种方式: 1. 原始方式:按照JSON字符串自己来解析. 2. 通用方式[★★★★★]: ...

  3. [leetcode]_String to Integer (atoi)

    非常考虑思维全面性的一道题,考验是否能够考虑本问题的方方面面. 题目:将一个string转换为int.实现函数atoi()的功能. 先应该明确atoi()有哪些特殊功能:(正常的正负数情况我就不列了) ...

  4. VMware虚拟机升级过程中遇到的一点问题

    在将VWware由9.0升级到10.0的过程中,出现如下图的错误:        failed to create the requested registry key Key:Installer e ...

  5. android空鼠修改

    抛弃盒子自带遥控器后,又不满意改键红外遥控器,选择飞鼠及无线键鼠成为最终方案.问题是:菜单键如何实现!其实很简单:即插即用USB无线飞鼠及键鼠套装只涉及2个文件:system/usr/layout/G ...

  6. delphi TFileStream.create

    Value  Meaning  fmCreate Create a file with the given name. If a file with the given name exists, op ...

  7. C# 代码重启windows服务

    ServiceController service = new ServiceController("EnergyRecordService"); protected void b ...

  8. Eclipse 4.6 Neon, could not create the java virtual machine

    下了eclipse 4.6,打开报错:could not create the java virtual machine. a fatal exception has occurred. 命令行用 e ...

  9. python 装饰器(decorator)

    装饰器(decorator) 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 装饰器(decorator)是一种高级Python语 ...

  10. Requests:Python HTTP Module学习笔记(二)(转)

    在上一篇日志中对Requests做了一个整体的介绍,接来下再介绍一些高级的用法,主要资料还是翻译自官网的文档,如有错漏,欢迎指正. 参考资料:http://docs.python-requests.o ...