Robot

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 158    Accepted Submission(s): 46

Problem Description
Michael has a telecontrol robot. One day he put the robot on a loop with n cells. The cells are numbered from 1 to n clockwise.

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
There are multiple test cases. 
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
For each test case in the input, you should output a line with the expected possibility. Output should be round to 4 digits after decimal points.
 
Sample Input
3 1 1 2
1
5 2 4 4
1
2
0 0 0 0
 
Sample Output
0.5000
0.2500
 
Source
 
 
 
 
 
按照概率DP过去,比较暴力,T_T
 
 /* **********************************************
Author : kuangbin
Created Time: 2013/8/10 11:51:05
File Name : F:\2013ACM练习\比赛练习\2013杭州邀请赛重现\1001.cpp
*********************************************** */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
using namespace std;
double dp[][];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,m,l,r;
while(scanf("%d%d%d%d",&n,&m,&l,&r) == )
{
if(n == && m == && l == && r == )break;
dp[][] = ;
for(int i = ;i < n;i++)dp[][i] = ;
int now = ;
while(m--)
{
int v;
scanf("%d",&v);
for(int i = ;i < n;i++)
dp[now^][i] = 0.5*dp[now][(i-v+n)%n] + 0.5*dp[now][(i+v)%n];
now ^= ;
}
double ans = ;
for(int i = l-;i < r;i++)
ans += dp[now][i];
printf("%.4lf\n",ans);
}
return ;
}
 

HDU 4576 Robot (很水的概率题)的更多相关文章

  1. HDU 4576 Robot(概率dp)

    题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...

  2. HDU 4576 Robot (概率DP)

    暴力DP求解太卡时间了...........写挫一点就跪了 //hdu robot #include <cstdio> #include <iostream> #include ...

  3. HDU 4576 Robot (概率 & 期望)

    Robot Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Sub ...

  4. HDU 4576 Robot(概率dp)

    Robot Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Sub ...

  5. HDU - 4576 Robot(概率dp+滚动数组)

    题意:所有的格子围成一个圈,标号为1~n,若从格子1出发,每次指令告知行走的步数,但可能逆时针也可能顺时针走,概率都是1/2,那么问走了m次指令后位于格子l~r(1≤l≤r≤n)的概率. 分析: 1. ...

  6. HDU 4593 Robot (水题)

    题意:有 n 个数,其中有两个数中相同的,让你找出这个数. 析:太简单了么,只要用数组下标记一下这个数的数量即可. 代码如下: #include <iostream> #include & ...

  7. HDU 5985/nowcoder 207D - Lucky Coins - [概率题]

    题目链接:https://www.nowcoder.com/acm/contest/207/D 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5985 ...

  8. HDU 2843 I Will Win(概率题?,怨念颇深,简单)

    题目 真不想说什么,,,这神题真讨厌,,,多校的.. //又是一道神题... #include<stdio.h> #include<string.h> //最大公约数 int ...

  9. HDU 4576 Robot

    思路 概率dp 既然是求概率,顺推 显然有转移\(dp[i][j]=dp[i-1][j-w]/2+dp[i-1][w]/2\) 然后是环,注意特判一下 环上不要用取模处理循环的情况,会被卡常 代码 # ...

随机推荐

  1. CentOS7手动编译安装内核4.11.7

    1. 进入/usr/src/目录 cd /usr/src 2. 下载内核源码,网址:https://www.kernel.org wget https://cdn.kernel.org/pub/lin ...

  2. 64_g4

    gnatcoll-2014-10.fc26.x86_64.rpm 28-Feb-2017 17:44 1738266 gnatcoll-devel-2014-10.fc26.i686.rpm 28-F ...

  3. vs 预编译命令行

    xcopy "$(SolutionDir)\Transight_FY_DataExchange_UI\CuscapiUpdaterServer.xml"  /i /d /y

  4. 根据节点解析xml

    config.xml文件如下: <?xml version="1.0" encoding="gb2312" ?> <root> < ...

  5. P1466 集合 Subset Sums(01背包求填充方案数)

    题目链接:https://www.luogu.org/problem/show?pid=1466 题目大意:对于从1到N (1 <= N <= 39) 的连续整数集合,能划分成两个子集合, ...

  6. hihocoder 1177 : 顺子

    #1177 : 顺子 时间限制:6000ms 单点时限:1000ms 内存限制:256MB 描述 你在赌场里玩梭哈,已经被发了4张牌,现在你想要知道发下一张牌后你得到顺子的概率是多少? 假定赌场使用的 ...

  7. 自定制Form组件

    代码 import re import copy class ValidateError(Exception): def __init__(self,detail): self.detail = de ...

  8. redis之(五)redis的散列类型的命令

    [一]赋值与取值 -->命令:HSET key field value   -->往某个key的某个属性设置值 -->命令:HGET key field   --> 获取某个k ...

  9. hdu 2818(并查集,带权更新)

    Building Block Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  10. 如何将json拼接在url后面当做地址栏参数?

    function param(data) { let url = '' for (var k in data) { let value = data[k] !== undefined ? data[k ...