HDU 4576 Robot(概率dp)
Robot
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 5906 Accepted Submission(s): 1754
Problem Description
At first the robot is in cell 1. Then Michael uses a remote control to send m commands to the robot. A command will make the robot walk some distance. Unfortunately the direction part on the remote control is broken, so for every command the robot will chose a direction(clockwise or anticlockwise) randomly with equal possibility, and then walk w cells forward.
Michael wants to know the possibility of the robot stopping in the cell that cell number >= l and <= r after m commands.
Input
Each test case contains several lines.
The first line contains four integers: above mentioned n(1≤n≤200) ,m(0≤m≤1,000,000),l,r(1≤l≤r≤n).
Then m lines follow, each representing a command. A command is a integer w(1≤w≤100) representing the cell length the robot will walk for this command.
The input end with n=0,m=0,l=0,r=0. You should not process this test case.
Output
Sample Input
1
5 2 4 4
1
2
0 0 0 0
Sample Output
0.2500
分析
code
#include<cstdio>
#include<algorithm>
#include<cstring> using namespace std; double f[][];
// f[i][j]到第i次操作,位置j上的概率 int main() { int n,m,l,r;
while (~scanf("%d%d%d%d",&n,&m,&l,&r) && n+m+l+r) {
memset(f,,sizeof(f));
f[][] = 1.0;
int cur = ;
for (int w,i=; i<=m; ++i) {
scanf("%d",&w);
w = w%n;
cur = cur^;
for (int k=; k<=n; ++k) {
f[cur][k] = f[cur^][k+w>n?k+w-n:k+w]/2.0 + f[cur^][k-w<?k-w+n:k-w]/2.0;
}
}
double ans = 0.0;
for (int i=l; i<=r; ++i) ans += f[cur][i];
printf("%.4lf\n",ans);
}
return ;
}
HDU 4576 Robot(概率dp)的更多相关文章
- HDU 4576 Robot(概率dp)
题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...
- hdu 4576(简单概率dp | 矩阵优化)
艰难的一道题,体现出菜菜的我... 首先,先吐槽下. 这题到底出题人是怎么想的,用普通概率dp水过??? 那为什么我概率dp写的稍微烂点就一直tle? 感觉很不公平.大家算法都一致,因为我程序没有那 ...
- HDU 4576 Robot (很水的概率题)
Robot Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Sub ...
- hdu 4576 (简单dp+滚动数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 题意:给出1~n的环,m个操作,每次能顺时针或逆时针走w步,询问最后在l~r这段区间内概率.(1 ...
- HDU 3853LOOPS(简单概率DP)
HDU 3853 LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...
- HDU - 1099 - Lottery - 概率dp
http://acm.hdu.edu.cn/showproblem.php?pid=1099 最最简单的概率dp,完全是等概率转移. 设dp[i]为已有i张票,还需要抽几次才能集齐的期望. 那么dp[ ...
- HDU 4405 【概率dp】
题意: 飞行棋,从0出发要求到n或者大于n的步数的期望.每一步可以投一下筛子,前进相应的步数,筛子是常见的6面筛子. 但是有些地方可以从a飞到大于a的b,并且保证每个a只能对应一个b,而且可以连续飞, ...
- HDU 4599 Dice (概率DP+数学+快速幂)
题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n ...
- [HDU 4089]Activation[概率DP]
题意: 有n个人排队等着在官网上激活游戏.Tomato排在第m个. 对于队列中的第一个人.有以下情况: 1.激活失败,留在队列中等待下一次激活(概率为p1) 2.失去连接,出队列,然后排在队列的最后( ...
- hdu 3853 LOOPS 概率DP
简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...
随机推荐
- 笨办法学Python(二十八)
习题 28: 布尔表达式练习 上一节你学到的逻辑组合的正式名称是“布尔逻辑表达式(boolean logic expression)”.在编程中,布尔逻辑可以说是无处不在.它们是计算机运算的基础和重要 ...
- April 15 2017 Week 15 Saturday
Attitude is a little thing that makes a big difference. 小态度,大不同. Attitudes can make a big difference ...
- ABAP Netweaver和Hybris Enterprise Commerce Platform的登录认证
ABAP Netweaver 在我的博客Learn more detail about Standard logon procedure里有详细介绍. Hybris ECP Hybris Admini ...
- Selenium入门系列5 默认不显示的下拉列表元素操作
本节课程的下拉框是那种默认隐藏,当鼠标移到菜单上下拉框才显示的.如果直接getelement会报错,提示元素不可见: so,得先让下拉列表显示出来再获取元素 用到的新知识: is_display() ...
- Selenium入门系列2 窗口大小控制
selenium控制窗口最大化.适合手机的宽度.适合pad的宽度等尝试下实例,网站是否做了响应式布局 #coding=utf-8 # 改变浏览器窗口大小.前进后退 from selenium impo ...
- framework7中一行的字如果过多就省略号显示的CSS写法
.order-info-title { text-overflow: ellipsis !important; white-space: nowrap !important; overflow: hi ...
- js 去掉指定符号的字符串做法
//去掉字符串末尾指定符号 function RemoveSymbol(str, symbol) { if (str.charAt(str.length - 1) == symbol) { str = ...
- The service command supports only basic LSB actions (start, stop, restart, try-restart, reload,force-reload, status)
# service iptables save The service command supports only basic LSB actions (start, stop, restart, t ...
- 近期流行的JavaScript框架与主题
[新年快乐]2017年你应该关注的JavaScript框架与主题 2017-01-01 王下邀月熊 JavaScript JavaScript的繁荣促生了很多优秀的技术.框架与工具库,这空前的繁荣也给 ...
- 2018.7.30 Oracle的Blog数据库类型读取和存
package com.lanqiao.shopping.test; import java.io.BufferedInputStream; import java.io.BufferedOutput ...