HDU2438:Turn the corner(三分)
传送门
分析

根据这张图,我们只要使得h<=y即可,可以发现h是一个凸函数,故使用三分,具体见代码
代码
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const double eps = 1e-7;
const double pi = acos(-1.0);
#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
#pragma comment(linker, "/STACK:102400000,102400000")
inline void read(int &x){x=0; char ch=getchar();while(ch<'0') ch=getchar();while(ch>='0'){x=x*10+ch-48; ch=getchar();}}
double x,y,l,w;
double calc(double ret)
{
double s,h;
s=l*cos(ret)+w*sin(ret)-x;
h=s*tan(ret)+w*cos(ret);
return h;
}
int main()
{
while(scanf("%lf%lf%lf%lf",&x,&y,&l,&w)!=EOF)
{
double left=0,right=pi/2;
while(right-left>eps)
{
double lm=left+(right-left)/3.0;
double rm=right-(right-left)/3.0;
if(calc(lm)<calc(rm)) left=lm;
else right=rm;
}
if(calc(left)<=y) puts("yes");else puts("no");
}
}
HDU2438:Turn the corner(三分)的更多相关文章
- HDU 2438 Turn the corner(三分查找)
托一个学弟的福,学了一下他的最简便三分写法,然后找了一道三分的题验证了下,AC了一题,写法确实方便,还是我太弱了,漫漫AC路!各路大神,以后你们有啥好的简便写法可以在博客下方留个言或私信我,谢谢了! ...
- hdu 2438 Turn the corner [ 三分 ]
传送门 Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU2438 Turn the corner【三分法】【数学几何】
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Turn the corner (三分)
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- hdu 2348 Turn the corner(三分&&几何)(中等)
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 【三分法】hdu2438 Turn the corner
Problem Description Mr. West bought a new car! So he is travelling around the city.One day he comes ...
- Turn the corner
Problem Description Mr. West bought a new car! So he is travelling around the city. One day he comes ...
- hdu 2438Turn the corner 三分
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- Turn the corner
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
随机推荐
- [WASM] Run WebAssembly in Node.js using the node-loader
WebAssembly is great for targeting performance bottlenecks in the browser. Now with node-loader, we ...
- C#.net word excel powerpoint (ppt) 转换成 pdf 文件
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- mysql (primary key)_(unique key)_(index) difference
MYSQL index MYSQL索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都以B-树的形式保存.如果没有索引,执行查询时MySQL必须从第一个记录开始扫描整个表的所有记录,直至找 ...
- BAT&注册表重定向劫持
RunJS 常用引导,有时启动某个应用需要环境变量可以这样启动应用,会对启动的进程生效,即被继承 set PATH=D:\Developer\sdk\platform-tools;%PATH% D: ...
- subclassdlgitem
subclassdlgitem 该函数用来子类化一个控件. Subclass(子类化)是MFC中最常用的窗体技术之一.子类化完成两个工作:一是把窗体类对象attach到一个windows窗体实体中(即 ...
- Swift开发教程--怎样播放图片动画
废话少说,直接上代码: var barsAnim = UIImageView(frame: self.view.frame); barsAnim.animationImages = NSArray() ...
- 使用NetBeans生成jar包,并在jar包中添加资源
在NetBeans中,执行Clean and Build便可得到jar文件 若要在jar中添加资源,先用压缩软件打开jar,然后将资源拖进当前归档文件即可 使用Class.getResource(St ...
- MRP 中的数据元素
20170227 MRP 元素是个什么东西? 系统显示的是MRP 元素缩写,程序用的是Code SimReq 简单需求AR 相关预订 OrdRes 订单需求BA 采购申请 PurRqs 采购申请BB ...
- (linux)SD卡初始化-mmc_sd_init_card函数(续)
转自:http://www.cnblogs.com/fengeryi/p/3472728.html mmc_sd_init_card剩下的关于UHS-I的分支结构. uhs-I的初始化流程图如 ...
- 修改STM32库函数中的晶振值
STM32F407的库文件中默认晶振值为25MHz,若外接晶振8MHz,则需修改以下几个地方: 1)修改HSE_VALUE的值 将#define HSE_VALUE ((uint32_t)250000 ...