HDU 4576 Robot (很水的概率题)
Robot
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 158 Accepted Submission(s): 46

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.
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.
1
5 2 4 4
1
2
0 0 0 0
0.2500
/* **********************************************
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 (很水的概率题)的更多相关文章
- HDU 4576 Robot(概率dp)
题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...
- HDU 4576 Robot (概率DP)
暴力DP求解太卡时间了...........写挫一点就跪了 //hdu robot #include <cstdio> #include <iostream> #include ...
- HDU 4576 Robot (概率 & 期望)
Robot Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Sub ...
- HDU 4576 Robot(概率dp)
Robot Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Sub ...
- HDU - 4576 Robot(概率dp+滚动数组)
题意:所有的格子围成一个圈,标号为1~n,若从格子1出发,每次指令告知行走的步数,但可能逆时针也可能顺时针走,概率都是1/2,那么问走了m次指令后位于格子l~r(1≤l≤r≤n)的概率. 分析: 1. ...
- HDU 4593 Robot (水题)
题意:有 n 个数,其中有两个数中相同的,让你找出这个数. 析:太简单了么,只要用数组下标记一下这个数的数量即可. 代码如下: #include <iostream> #include & ...
- HDU 5985/nowcoder 207D - Lucky Coins - [概率题]
题目链接:https://www.nowcoder.com/acm/contest/207/D 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5985 ...
- HDU 2843 I Will Win(概率题?,怨念颇深,简单)
题目 真不想说什么,,,这神题真讨厌,,,多校的.. //又是一道神题... #include<stdio.h> #include<string.h> //最大公约数 int ...
- HDU 4576 Robot
思路 概率dp 既然是求概率,顺推 显然有转移\(dp[i][j]=dp[i-1][j-w]/2+dp[i-1][w]/2\) 然后是环,注意特判一下 环上不要用取模处理循环的情况,会被卡常 代码 # ...
随机推荐
- Python基础=== Tkinter Grid布局管理器详解
本文转自:https://www.cnblogs.com/ruo-li-suo-yi/p/7425307.html @ 箬笠蓑衣 Grid(网格)布局管理器会将控件放置到一个二维的表 ...
- 简单的自动化运维工具(shell+except+whiptail+功能模块化函数+循环)
简单的自动化运维工具(shell+except+whiptail+功能模块化函数+循环) http://www.cnblogs.com/M18-BlankBox/p/5881700.html
- 更新T1表,要添加一个条件A,但T1表没有A字段
可以这样 如果T2表有A字段,T1.T2表有共同字段B,可以通过T2表A字段为条件查得B字段 再用B字段为条件去更新T1表 update T1 set C = '1' where B in(selec ...
- C json实战引擎 二 , 实现构造部分
引言 这篇博文和前一篇 C json实战引擎一,实现解析部分设计是相同的,都是采用递归下降分析. 这里扯一点 假如你是学生 推荐一本书 给 大家 自制编程语言 http://baike.baidu.c ...
- leetcode 121 122 123 . Best Time to Buy and Sell Stock
121题目描述: 解题:记录浏览过的天中最低的价格,并不断更新可能的最大收益,只允许买卖一次的动态规划思想. class Solution { public: int maxProfit(vector ...
- leetcode 之LRU Cache(26)
很实际的一道题.定义一个双向链表list,方便插入和删除:定义一个哈希表,方便查找. 具体的,哈希表存放每个结点的key和它对应的结点的地址:访问结点时,如果结点存在,则将其交换到头部,同是更新哈希表 ...
- 利用BeanUtils工具类封装表单数据
一.BeanUtils工具类的使用 1.首先导入BeanUtils工具类的jar包 commons-beanutils-1.8.0.jar commons-logging-1.1.1.jar 2.se ...
- Search for a Range——稍微升级版的二分查找
Given a sorted array of integers, find the starting and ending position of a given target value. You ...
- [转]windows消息机制(MFC)
消息分类与消息队列 Windows中,消息使用统一的结构体(MSG)来存放信息,其中message表明消息的具体的类型, 而wParam,lParam是其最灵活的两个变量,为不同的消息类型时,存放数据 ...
- 【剑指offer】面试题 55. 二叉树的深度
面试题 55. 二叉树的深度 题目一:二叉树的深度 题目描述:输入一棵二叉树,求该树的深度.从根结点到叶结点依次经过的结点(含根.叶结点)形成树的一条路径,最长路径的长度为树的深度. Java 实现 ...