Aizu 2309 Sleeping Time DFS
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:
- Begin with the numbers K, R and L.
- She tries to sleep for H=(R+L)/2 hours.
- If she feels the time is longer than or equal to the optimal length, then update L with H. Otherwise, update R with H.
- 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 30, 0 \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 1, 0 \leq E \leq 12, 0 \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的
@)1%KBO0HM418$J94$1R.jpg)
代码:
#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的更多相关文章
- Aizu 2306 Rabbit Party DFS
Rabbit Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view. ...
- Aizu 2301 Sleeping Time(概率,剪枝)
根据概率公式dfs即可,判断和区间[T-E,T+E]是否有交,控制层数. #include<bits/stdc++.h> using namespace std; int K,R,L; d ...
- Aizu 2300 Calender Colors dfs
原题链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2300 题意: 给你一个图,让你生成一个完全子图.使得这个子图中每个点的最 ...
- Aizu - 2306 Rabbit Party (DFS图论)
G. Rabbit Party Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO f ...
- 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 ...
- Aizu 0033 Ball(dfs,贪心)
日文题面...题意:是把一连串的有编号的球往左或者往右边放.问能不能两边都升序. 记录左边和右边最上面的球编号大小,没有就-1,dfs往能放的上面放. #include<bits/stdc++. ...
- Aizu - 2305 Beautiful Currency (二分 + DFS遍历)
F. Beautiful Currency Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit intege ...
- 【Aizu - 0525】Osenbei (dfs)
-->Osenbei 直接写中文了 Descriptions: 给出n行m列的0.1矩阵,每次操作可以将任意一行或一列反转,即这一行或一列中0变为1,1变为0.问通过任意多次这样的变换,最多可以 ...
- Aizu 0531 "Paint Color" (坐标离散化+DFS or BFS)
传送门 题目描述: 为了宣传信息竞赛,要在长方形的三合板上喷油漆来制作招牌. 三合板上不需要涂色的部分预先贴好了护板. 被护板隔开的区域要涂上不同的颜色,比如上图就应该涂上5种颜色. 请编写一个程序计 ...
随机推荐
- PLSQL Developer调试 存储过程和触发器
1. 打开PL/SQL Developer如果 在机器上安装了PL/SQL Developer的话,打开PL/SQL Developer界面输入 用户名,密码和host名字,这个跟在程序中web.co ...
- 十个拥有丰富UI组件的JS开发框架
如今,网上有各种各样的 JavaScript 框架用来简化 Web 应用开发.这些框架都提供了一些核心的特性,例如 DOM 操作,动画,事件处理以及 Ajax 交互,但不是都带有 UI 组件.今天这篇 ...
- 浅谈JavaBean,Entity Bean,Enterprise Bean等Bean以及POJO的含义
一.对于java bean,就是一个java模型组件,他为使用java类提供了一种标准的格式,在用户程序和可视化管理工具中可以自动获得这种具有标准格式的类的信息,并能够创建和管理这些类. jav ...
- 【转】报错:Program "sh" not found in PATH
原文网址:http://www.cnblogs.com/SadNight/p/3406201.html (1) 报错:Program "sh" not found in PATH ...
- Parallel for-each loops in .NET C# z
An IEnumerable object An Action of T which is used to process each item in the list List<string&g ...
- 4种activity的启动模式
在android里,有4种activity的启动模式,分别为: “standard” (默认) “singleTop” “singleTask” “singleInstance” 它们主要有如下不同: ...
- UVA 11183 Teen Girl Squad 最小树形图
最小树形图模板题 #include <iostream> #include <algorithm> #include <cstdio> #include <c ...
- 那些年一起踩过的坑 — java 自动装箱拆箱问题
坑在哪里? 我们都知道Java的八种基本数据类型:int, short, long, double, byte, char, float, boolean 分别有各自对应的包装类型:Integ ...
- 黑盒测试用例设计方法&理论结合实际 -> 错误推断法
一 概念 基于经验和直觉推测程序中所有可能存在的各种错误, 从而有针对性的设计测试用例的方法. 二 错误推断法的应用 基本思想:列举出程序中所有可能有的错误和容易发生错误的特殊情况,根据他们选择测试 ...
- 反编译c#的相关问题
最近硬盘坏掉了,有一个项目没有备份,只好用Exe 文件反编译出来用,查了一下相关的文章用到的工具如下: ILSpy_Master_2.1.0.1603_RTW_Binaries 直接生成时,有些奇怪, ...