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. Overview Of Portal Registry And Content References

     Portal Registry Each portal is defined by a portal registry.A portal registry has a tree-like struc ...

  2. C#中如何将combox中的下拉项和一个枚举中的各项进行绑定

    实现一个combobox,将其各个下拉项与枚举进行绑定 效果图如下: 代码详解如下: 枚举: public enum StoreSite { /// <summary> /// 未知 // ...

  3. HTML5+CSS3前端开发资源整合

    HTML5+CSS3前端开发资源整合   推个广告 个人网站:http://www.51pansou.com HTML5视频下载:HTML5视频 HTML5源码下载:HTML5源码 meta相关: & ...

  4. 深入浅出MongoDB(一)NoSQL

    从本文开始,我们一起学习一下MongoDB相关内容,在学习MongoDB之前,首先要做的就是学习NoSQL. 为什么要学习NoSQL,原因很简单,因为MongoDB是NoSQL数据库的一种,换言之,如 ...

  5. Oracle之Linux下核心参数

    kernel.shmmax 用于定义单个共享内存段的最大值: 建议一个大的共享内存段能容纳整个SGA,这样在任何时候都不会有性能下降的隐患: 建议:32位Linux 物理内存大于4G 的设置为4G 即 ...

  6. linux下的mount命令的用法详解

    挂接命令(mount) 首先,介绍一下挂接(mount)命令的使用方法,mount命令参数非常多,这里主要讲一下今天我们要用到的. 命令格式:mount [-t vfstype] [-o option ...

  7. hdu 1412 {A} + {B}

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3282 {A} + {B} Description 给你两个集合,要求{A} + {B}.注:同一个集合 ...

  8. 无法在 Android 模拟器上访问本机的Web服务的解决办法

    我在本地跑了一个 Tomcat ,我想在 Android 模拟器中直接通过下面的 url 地址访问 Tomcat 上的服务 http://192.168.0.20:8080/getweather 但是 ...

  9. Oracle用户,权限,角色以及登录管理 scoot 授权

    Oracle用户,权限,角色以及登录管理 1. sys和system用户的区别 system用户只能用normal身份登陆em.除非你对它授予了sysdba的系统权限或者syspoer系统权限. sy ...

  10. Boolean.parseBoolean("true") 和 Boolean.getBoolean("true");的区别及用法

    正确用法:boolean repeatIndicator = Boolean.valueOf("true").booleanValue();或者也可以使用Boolean.parse ...