URAL 1066 Garland 二分
二分H2的位置,判断条件为是否有Hi < 0
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath> using namespace std; const double eps = 1e-; int N;
double A; int dcmp( double a )
{
if ( fabs(a) < eps ) return ;
return a < ? - : ;
} bool cal( double mid, double &ans )
{
double Hi2 = A, Hi1 = mid, Hi0;
for ( int i = ; i < N - ; ++i )
{
Hi0 = 2.0 * ( Hi1 + 1.0 ) - Hi2;
if ( dcmp( Hi0 ) < ) return false;
Hi2 = Hi1, Hi1 = Hi0;
}
ans = Hi0;
return true;
} int main()
{
while ( ~scanf( "%d%lf", &N, &A ) )
{
double l = 0.0, r = A;
//int cnt = 0;
double ans;
while ( dcmp( r - l ) > )
{
//++cnt;
double mid = ( l + r ) / 2.0;
//printf( "%f %f %f\n", l, r, mid );
double tmp;
if ( !cal( mid, tmp ) ) l = mid;
else
{
r = mid;
ans = tmp;
}
//if ( cnt > 100 ) break;
}
printf( "%.2f\n", ans );
}
return ;
}
URAL 1066 Garland 二分的更多相关文章
- POJ 1759 Garland(二分+数学递归+坑精度)
POJ 1759 Garland 这个题wa了27次,忘了用一个数来储存f[n-1],每次由于二分都会改变f[n-1]的值,得到的有的值不精确,直接输出f[n-1]肯定有问题. 这个题用c++交可以 ...
- POJ1759 Garland —— 二分
题目链接:http://poj.org/problem?id=1759 Garland Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- ural 1066 uva 1555
好吧 竟然因为编译器的问题不过 到底有什么区别 ???? 可以推出公式Hi = (i-1)H2 +(i-1)(i-2)-(i-2)*H1 因为所有的Hi都要大于零 Hn要最小 即存在Hi=0 ...
- 二分法&三分法
ural History Exam 二分 #include <iostream> #include <cstdlib> using namespace std; //二分 ...
- POJ 1759 Garland(二分答案)
[题目链接] http://poj.org/problem?id=1759 [题目大意] 有n个数字H,H[i]=(H[i-1]+H[i+1])/2-1,已知H[1],求最大H[n], 使得所有的H均 ...
- URAL - 1486 Equal Squares 二维哈希+二分
During a discussion of problems at the Petrozavodsk Training Camp, Vova and Sasha argued about who o ...
- URAL 1948 H - The Robot on the Line 二分 + 数学
http://acm.hust.edu.cn/vjudge/contest/126149#problem/H 给定一条二次函数 f (x) = a * x * x + b * x + c 求一个最小的 ...
- 【URAL 1486】Equal Squares(二维哈希+二分)
Description During a discussion of problems at the Petrozavodsk Training Camp, Vova and Sasha argued ...
- URAL 1822. Hugo II's War 树的结构+二分
1822. Hugo II's War Time limit: 0.5 second Memory limit: 64 MB The glorious King Hugo II has declare ...
随机推荐
- android 开发 drawerlayout出现退不回去的情况
问题原因: id_framelayout2 写在 id_linearlayout2 的后面了: 注意记得写: android:layout_gravity="start" 正确: ...
- HDU 5592 ZYB's Premutation
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5592 题意: http://bestcoder.hdu.edu.cn/contests/contes ...
- 【CentOS】安装配置vncserver
参考资料: http://my.oschina.net/yankunren/blog/70042 安装过程 (1).检查vncserver是否已经安装 [root@Nginx canyouNgx]# ...
- JS 学习笔记--13---原型
练习中使用的是IE11,如果有错误之处,还请各位朋友多多指教.本文关于原型难以描述,故多用代码展示 原型是JS中一个很重要的概念,也是JS中一个难点,语言上难以描述,原型对象的属性和方法叫做原型属性和 ...
- AVFoundation的使用
AVFoundation的使用 2013-05-03 14:50:21| 分类: iphone_dev_note|举报|字号 订阅 相机相关应用一般会用到AVFoundation. ...
- HDAO one error
对normal target设置的background clearcolor 导致 远处天空 通过了 normalRejectTest 所以要对normal target单独设置 不能通过test的 ...
- 用boost共享内存实现进程通信的例子
发送端 #include "DBProc1.h" #include <string> #include <thread> #include <boos ...
- .NET设计模式(15):结构型模式专题总结(转)
摘要:结构型模式,顾名思义讨论的是类和对象的结构,它采用继承机制来组合接口或实现(类结构型模式),或者通过组合一些对象,从而实现新的功能(对象结构型模式).这些结构型模式,它们在某些方面具有很大的相似 ...
- Android 4.4 KitKat, the browser and the Chrome WebView
Having V8 as the JavaScript engine for the new web view, the JavaScript performance if much better, ...
- 如何做到尽可能不使用庞大的jQuery
jQuery 是现在最流行的 JavaScript 工具库. 据统计,目前全世界 57.3% 的网站使用它.也就是说,10 个网站里面,有 6 个使用 jQuery.如果只考察使用工具库的网站,这个比 ...