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. python基础===open()文件处理使用介绍

    本文转自:Python open()文件处理使用介绍 1. open()语法open(file[, mode[, buffering[, encoding[, errors[, newline[, c ...

  2. 【bzoj4518】征途

    懒得推式子了,总之是个斜率优化…… 先化一下题目要求的式子,再写一下dp方程,然后就是很自然的斜率优化了qwq #include<bits/stdc++.h> #define N 3005 ...

  3. C中级 数据序列化简单使用和讨论 (二)

    引言 - 一种更好的方式 其实不管什么语言, 开发框架都会遇到序列化问题. 序列化可以理解为A 和 B 交互的一种协议.  很久以前利用 printf 和 scanf 的协议实现过一套序列化问题. C ...

  4. ios IAP 内购验证

    参考我之前的笔记 苹果内购笔记,在客户端向苹果购买成功之后,我们需要进行二次验证. 二次验证 IOS在沙箱环境下购买成功之后,向苹果进行二次验证,确认用户是否购买成功. 当应用向Apple服务器请求购 ...

  5. IE中部分版本的浏览器对Select标签设置innerHTML无效的问题

    这样写的代码:document.getElementById('data_list').innerHTML = data;//data是ajax返回的数据 结果发现在ie10的兼容模式下面下拉框没有内 ...

  6. Hierarchical Attention Based Semi-supervised Network Representation Learning

    Hierarchical Attention Based Semi-supervised Network Representation Learning 1. 任务 给定:节点信息网络 目标:为每个节 ...

  7. java生成缩略图,旋转,水印,截图

    转自:http://rensanning.iteye.com/blog/1545708 感谢,方便自己查看

  8. win10网速慢

    升级到win10之后发现网速特别慢,搜了下,网上的解决办法果然好使,按照如下操作即可. 返回桌面,按WIN+R键组合,运行gpedit.msc 打开组策略 依次展开管理模板->网络->Qo ...

  9. hdu 1495(BFS)

    非常可乐 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  10. Linux上安装MongoDB

    使用本教程使用.rpm 软件包在红帽企业Linux或CentOS Linux版本6和7上安装MongoDB Community Edition . 平台支持 本安装指南仅支持64位系统.详细信息请参见 ...