三分--Football Goal(面积最大)
Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
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.
of an arbitrary quadrangle.
Input
Output
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(面积最大)的更多相关文章
- ural 1874 Football Goal
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> u ...
- 【BZOJ1069】【SCOI2007】最大土地面积
题目大意:给定有n个点的点集,求该点集中任意四个点所构成的四边形中面积最大四边形的面积. 我们不难想到(不难yy出来),面积最大的四边形的四个顶点一定所给定的点集所构成的凸包上.我们求出给定点集的集合 ...
- POJ 3301 Texas Trip (三分)
题目链接 题意 : 给你若干个点,让你找最小的正方形覆盖这所有的点.输出面积. 思路 : 三分枚举正方形两对边的距离,然后求出最大,本题用的是旋转正方形,也可以用旋转点,即点的相对位置不变. 正方形从 ...
- [三分]HDOJ 5531 Rebuild
题意:给n个点,以这n个点为圆心画圆,使得所有的圆与其相邻的圆相切. 求n个圆最小的面积和. 分析:很容易想到确定了其中一个圆的半径之后,其他的圆的半径也能随之确定了. 画一画三个点的和四个点的,会发 ...
- UVA 10194 Football (aka Soccer)
Problem A: Football (aka Soccer) The Problem Football the most popular sport in the world (america ...
- HDU-1225 Football Score
http://acm.hdu.edu.cn/showproblem.php?pid=1225 一道超级简单的题,就因为我忘记写return,就wa好久,拜托我自己细心一点. 学习的地方:不过怎么查找字 ...
- HDU_2036——多边形面积,行列式计算
Problem Description “ 改革春风吹满地, 不会AC没关系; 实在不行回老家, 还有一亩三分地. 谢谢!(乐队奏乐)”话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也 ...
- poj3301 三分
Texas Trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4998 Accepted: 1559 Descri ...
- n多边形面积
“ 改革春风吹满地,不会AC没关系;实在不行回老家,还有一亩三分地.谢谢!(乐队奏乐)” 话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是云里雾里,而且,还竟然来这么几句打油诗.好呀 ...
随机推荐
- aspx页面中用Input 标签实现上传图片功能
实现上传图片功能需单独的建立一个aspx页面, 其中前台页面需要注意两点: a)实现上传功能的input的type="file" b)设置请求报文头为 enctype=" ...
- c#中执行多条sql语句【ORA-00911: 无效字符】
问题描述: 在plsql里执行多条sql语句的时候,使用“,”(逗号)分隔,测试可以执行多条,而在C#执行多条sql语句的时候[ORA-00911: 无效字符]. 有时我们需要一次性执行多条sql语句 ...
- centos内核优化--转至网络
A.关闭selinux(可以预防nginx修改根目录后访问出现404或者403) vi /etc/selinux/config SELINUX=disabled B.修改打开最大文件数句柄也就是 so ...
- 对phpcms中{L('news')}的讲解
直切话题 对于phpcms分M,C,A,那么现在要讲解的L是跟着M走的,每个M在languages中都有一个.lang.php文件,如Mcontent,就有一个content.lang.php,找到对 ...
- Library工程No resource identifier found for attribute
使用library工程中自定义属性无法识别问题 解决:xmlns:ptr="http://schemas.android.com/apk/res/包名, 改成xmlns:ptr=" ...
- SQL Server 基础之《学生表-教师表-课程表-选课表》
一.数据库表结构及数据 建表 CREATE TABLE Student ( S# INT, Sname ), Sage INT, Ssex ) ) CREATE TABLE Course ( C# I ...
- 访问svc 文件,编译器错误消息: CS0016,未能写入输出文件
编译错误 说明: 在编译向该请求提供服务所需资源的过程中出现错误.请检查下列特定错误详细信息并适当地修改源代码. 编译器错误消息: CS0016: 未 ...
- m3u8
audo apt-get install pkg-configsudo apt-get install automake autoconf m4 libtool sudo apt-get instal ...
- spring事物的七种事物传播属性行为及五种隔离级别
首先,说说什么事务(Transaction). 事务,就是一组操作数据库的动作集合.事务是现代数据库理论中的核心概念之一.如果一组处理步骤或者全部发生或者一步也不执行,我们称该组处理步骤为一个事务.当 ...
- MIFARE系列8《D8M1.exe》
软件名:D8M1.exe 更新时间:2014.06.28 操作系统:windowAll 外部设备:D8读卡器 D8M1可以对MIFARE块读写操作,支持1K,4K.检验KEY后返回SAK,QTAQ,U ...