Sleeping Time

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93265#problem/B

Description

Miki is a high school student. She has a part time job, so she cannot take enough sleep on weekdays. She wants to take good sleep on holidays, but she doesn't know the best length of sleeping time for her. She is now trying to figure that out with the following algorithm:

  1. Begin with the numbers KR and L.
  2. She tries to sleep for H=(R+L)/2 hours.
  3. If she feels the time is longer than or equal to the optimal length, then update L with H. Otherwise, update R with H.
  4. After repeating step 2 and 3 for K nights, she decides her optimal sleeping time to be T' = (R+L)/2.

If her feeling is always correct, the steps described above should give her a very accurate optimal sleeping time. But unfortunately, she makes mistake in step 3 with the probability P.

Assume you know the optimal sleeping time T for Miki. You have to calculate the probability PP that the absolute difference of T' and T is smaller or equal to E. It is guaranteed that the answer remains unaffected by the change of E in 10^{-10}.

Input

The input follows the format shown below

KRL
P
E
T

Where the integers 0 \leq K \leq 300 \leq R \leq L \leq 12 are the parameters for the algorithm described above. The decimal numbers on the following three lines of the input gives the parameters for the estimation. You can assume 0 \leq P \leq 10 \leq E \leq 120 \leq T \leq 12.

Output

Output PP in one line. The output should not contain an error greater than 10^{-5}.

Sample Input

3 0 2
0.10000000000
0.50000000000
1.00000000000

Sample Output

0.900000

HINT

题意

有个人要睡觉,他的睡觉是二分时间睡的……

他有p的概率二分错,然后问你他有多少的概率二分正确

题解:

就dfs就好了,类似线段树区间查询一样,可以在中间直接break的

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std; int n;double L,R,P,E,T;
double ans = ;
void dfs(int now,double l,double r,double p,double e,double t)
{ if(l>(T+E)&&(r>(T+E)))
return;
if(l<(T-E)&&r<(T-E))
return;
if(l<=(T+E)&&l>=(T-E)&&r<=(T+E)&&r>=(T-E))
{
ans+=p;
return;
}
double h = (l+r)/2.0;
if(now == n)
{
if(fabs(h-T)<=E)
ans += p;
return;
}
if(h-T>=-1e-)
{
dfs(now+,h,r,p*(P),e,t);
dfs(now+,l,h,p*(-P),e,t);
}
else
{
dfs(now+,l,h,p*(P),e,t);
dfs(now+,h,r,p*(-P),e,t);
}
}
int main()
{
scanf("%d",&n);
scanf("%lf%lf%lf%lf%lf",&L,&R,&P,&E,&T);
dfs(,L,R,,E,T);
printf("%.10lf\n",ans);
return ;
}

Aizu 2309 Sleeping Time DFS的更多相关文章

  1. Aizu 2306 Rabbit Party DFS

    Rabbit Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view. ...

  2. Aizu 2301 Sleeping Time(概率,剪枝)

    根据概率公式dfs即可,判断和区间[T-E,T+E]是否有交,控制层数. #include<bits/stdc++.h> using namespace std; int K,R,L; d ...

  3. Aizu 2300 Calender Colors dfs

    原题链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2300 题意: 给你一个图,让你生成一个完全子图.使得这个子图中每个点的最 ...

  4. Aizu - 2306 Rabbit Party (DFS图论)

    G. Rabbit Party Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO f ...

  5. Aizu 2302 On or Off dfs/贪心

    On or Off Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  6. Aizu 0033 Ball(dfs,贪心)

    日文题面...题意:是把一连串的有编号的球往左或者往右边放.问能不能两边都升序. 记录左边和右边最上面的球编号大小,没有就-1,dfs往能放的上面放. #include<bits/stdc++. ...

  7. Aizu - 2305 Beautiful Currency (二分 + DFS遍历)

    F. Beautiful Currency Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit intege ...

  8. 【Aizu - 0525】Osenbei (dfs)

    -->Osenbei 直接写中文了 Descriptions: 给出n行m列的0.1矩阵,每次操作可以将任意一行或一列反转,即这一行或一列中0变为1,1变为0.问通过任意多次这样的变换,最多可以 ...

  9. Aizu 0531 "Paint Color" (坐标离散化+DFS or BFS)

    传送门 题目描述: 为了宣传信息竞赛,要在长方形的三合板上喷油漆来制作招牌. 三合板上不需要涂色的部分预先贴好了护板. 被护板隔开的区域要涂上不同的颜色,比如上图就应该涂上5种颜色. 请编写一个程序计 ...

随机推荐

  1. poj3186 poj3267

    两道很不错的dp 3186很神似回文词,合并石子之类的问题: 一开始不知道怎么在dp方程中体现权值天数,很来才想起来 对于一段区间[i,j],里面的东西必然是要卖完的 又因为只能从两头开始卖,所以 d ...

  2. DataTable导出到Excel(.NET 4.0)

    最近在论坛里又看到很多关于DataTable(DataSet)导入Excel的帖子,我也温故知新一下,用VS2010重新整理了一个Sample.这个问题简化一下就是内存数据到文件,也就是遍历赋值,只不 ...

  3. UVa 221 (STL 离散化) Urban Elevations

    题意: 作图为n个建筑物的俯视图,右图为从南向北看的正视图,按从左往右的顺序输出可见建筑物的标号. 分析: 题中已经说了,要么x相同,要么x相差足够大,不会出现精度问题. 给这n个建筑物从左往右排序, ...

  4. Rman实现数据库迁移

    Rman实现数据库迁移(从库A迁移到库B)环境:服务器A:Oracle10g+AS3服务器B:Oracle10g+AS4准备工作: 1 在数据库B上建立与库A相同的目录结构(若由于磁盘空间等原因可以用 ...

  5. 15个极好的Linux find命令示例(二)

    前阵子,我们审查了15件实事 find命令的例子(第一部分).查找命令可以做很多比只是在寻找基于名称的文件 (第2部分)在这篇文章中,让我们来讨论15高级find命令的例子, 包括-根据它访问,修改或 ...

  6. 【转】UINavigationBar 使用总结

    原文网址:http://www.jianshu.com/p/f0d3df54baa6 UINavigationBar是我们在开发过程中经常要用到的一个控件,下面我会为大家介绍一些常用的用法. 1. 设 ...

  7. ubuntu桌面右上角键盘图标不见解决方法

    今天出现了这个问题,桌面右上角的键盘图标不见,找到解决方法如下: 打开终端,分别输入以下命令即可: killall ibus-daemon 这个表示结束进程 ibus-daemon -d 这个表示重启 ...

  8. UVA 11928 The Busy Dog

    题意:一只狗被拴在杆子上,从起点开始按直线依次跑到给出的点最后回到起点问绕杆子几圈,逆时针为正,顺时针为负,撞到杆子输出Ouch!. 解法:用叉积判断方向,用余弦定理求出以杆子为顶点的角,加和除以2π ...

  9. HDU 5694 BD String 递归暴力

    http://blog.csdn.net/angon823/article/details/51484906 #include <cstdio> #include <iostream ...

  10. I2c串行总线组成及其工作原理

    采用串行总线技术可以使系统的硬件设计大大简化,系统的体积减小,可靠性提高,同时系统更容易更改和扩充 常用的串行扩展总线有:I2c总线,单总线,SPI总线,以及microwire.Plus等等 I2c总 ...