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 ...
随机推荐
- /lib64/libc.so.6: version `GLIBC_2.14' not found问题
<备忘> 参考文章: https://my.oschina.net/zhangxu0512/blog/262275 问题答疑: http://blog.sina.com.cn/s/blog ...
- Web前端一种动态样式语言-- Less
变量 变量允许我们单独定义一系列通用的样式,然后在需要的时候去调用.所以在做全局样式调整的时候我们可能只需要修改几行代码就可以了. // LESS @color: #4D926F; #header { ...
- makefile常用函数
标签(空格分隔): makefile 1.字符串替换和分析函数 $(subst from,to,text) #在文本"text"中使用"to"替换每一处&quo ...
- 第九章 CSS-DOM
另一个网友整理了很多书中的代码:http://www.cnblogs.com/jingangel/archive/2013/01/03/2843505.html 1. 三位一体的网页 浏览器看到的网页 ...
- 【转】GCC编译使用动态链接库
相关gcc参数:-l -L -shared -fPIC -static -c -o 原文地址:[脚本之家]http://www.jb51.net/article/34990.htm 根据链 ...
- cygwin and its host machine
Senario 本来我是想要修改下 machine name 在Ubuntu中的步骤是这样的 1 sudo hostname newMechineName 2 sudo vi /etc/hostnam ...
- Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
题目链接: http://www.codeforces.com/contest/446/problem/A 题解: dp1[x]表示以x结尾的最大严格升序连续串,dp2[x]表示以x开头的最大严格升序 ...
- BitMap排序
问题描述: BitMap排序思想: 用1bit位标记某个元素对应的值 优点: 效率高,不允许进行比较和移位 ...
- iOS开发之runtime的运用-获取当前网络状态
之前写过runtime的一些东西,这次通过runtime获取一些苹果官方不想让你拿到的东西,比如,状态栏内部的控件属性.本文将通过runtime带你一步步拿到状态栏中显示网络状态的控件,然后通过监测该 ...
- 【转载】Redis与Memcached的区别
传统MySQL+ Memcached架构遇到的问题 实际MySQL是适合进行海量数据存储的,通过Memcached将热点数据加载到cache,加速访问,很多公司都曾经使用过这样的架构,但随着业务数据量 ...