hdu 4405 Aeroplane chess(简单概率dp 求期望)
Aeroplane chess
There are also M flight lines on the chess map. The i-th flight line can help Hzz fly from grid Xi to Yi (0<Xi<Yi<=N) without throwing the dice. If there is another flight line from Yi, Hzz can take the flight line continuously. It is granted that there is no two or more flight lines start from the same grid.
Please help Hzz calculate the expected dice throwing times to finish the game.
Input
Each test case contains several lines.
The first line contains two integers N(1≤N≤100000) and M(0≤M≤1000).
Then M lines follow, each line contains two integers Xi,Yi(1≤Xi<Yi≤N).
The input end with N=0, M=0.
Output
Sample Input
8 3
2 4
4 5
7 8
0 0
Sample Output
2.3441
Source
题意:
有一个飞行棋n个格子,刚开始在0这个位置,每次可以扔色子,扔到x则可以移动x格
如果到达的位置>=n则胜利
另外在棋盘上还有m对点x,y表示在位置x可以直接飞行到y
求到达胜利平均的扔色子次数
分析:
期望逆推。
d[i]表示到达 i 的时候还需要几次才能到达n。
初始d[n] = 0; 而d[0]就是所求的答案
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <algorithm>
#define LL __int64
const int maxn = 1e5+;
using namespace std;
double d[maxn];
int c[maxn]; int main()
{
int n, m, i, j;
while(~scanf("%d%d", &n, &m))
{
if(n== && m==) break;
memset(c, -, sizeof(c));
for(i = ; i < m; i++)
{
int a, b;
scanf("%d%d", &a, &b);
c[a] = b;
}
memset(d, , sizeof(d));
d[n] = ;
double t = 1.0/;
for(i = n-; i >= ; i--)
{
if(c[i]==-)
d[i] += 1.0 + d[i+]*t + d[i+]*t+d[i+]*t+d[i+]*t+d[i+]*t+d[i+]*t;
else
d[i] = d[c[i]];
}
printf("%.4f\n", d[]);
}
return ;
}
hdu 4405 Aeroplane chess(简单概率dp 求期望)的更多相关文章
- HDU 4405 Aeroplane chess (概率DP求期望)
题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...
- hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4405 Aeroplane chess(概率+dp)
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+ grids labeled to ...
- HDU-4405 Aeroplane chess(概率DP求期望)
题目大意:一个跳棋游戏,每置一次骰子前进相应的步数.但是有的点可以不用置骰子直接前进,求置骰子次数的平均值. 题目分析:状态很容易定义:dp(i)表示在第 i 个点出发需要置骰子的次数平均值.则状态转 ...
- Aeroplane chess(简单概率dp)
Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz start ...
- HDU3853-LOOPS(概率DP求期望)
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- HDU 4405:Aeroplane chess(概率DP入门)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description Hzz loves ...
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- POJ2096 Collecting Bugs(概率DP,求期望)
Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...
随机推荐
- 系统使用 aspose.cell , 使得ashx第一次访问会变很慢
网站放在IIS后, 在网站第一次访问后. 回收应用程序池 第一次访问aspx页面还是比较快. 但第一次访问ashx会很慢. 后发现原因: aspose.cell的5.3...版本. 的原 ...
- C#中实现VB中的CreateObject方法
经常看到有些VB的例子中直接用个CreateObject就可调用系统功能(大多是COM对象),像用户设定,网络设定等等.虽然C#中可以通过使用VB的命名空间的方法来调用CreateObject函数,但 ...
- openSSL漏洞原理及安全加固
2014年4月8日晚,互联网爆出了又一重量级安全漏洞,即CVE-2014-0160,通俗来讲就是OpenSSL出现了安全漏洞. 说 这个漏洞前,先介绍一下OpenSSL,OpenSSL是一个强大的安全 ...
- Codeforces Round #250 (Div. 2)
感觉不会再爱了,呜呜! A题原来HACK这么多!很多人跟我一样掉坑了! If there is some choice whose description at least twice shorter ...
- display:inline-block 在IE6中实现{转}
IE6/IE7下对display:inline-block的支持性不好. 1.inline元素的display属性设置为inline-block时,所有的浏览器都支持: 2.block元素的displ ...
- pyhton Chapter3 读文件
使用内置函数open()打开文件,data=open("1.txt").利用data.close()关闭文件.利用data.readline()读取文件中的一行数据,然后指示读取文 ...
- HDU 1098 Ignatius's puzzle(数学归纳)
以下引用自http://acm.hdu.edu.cn/discuss/problem/post/reply.php?postid=8466&messageid=2&deep=1 题意以 ...
- Linux网络编程7——使用TCP实现双方聊天
思路 主线程负责发送消息,另一线程负责接收消息.服务端和客户端均是如此. 注意 当A方close掉用于通信的socket端口后,该端口是不会立即关闭的.因为此时可能B方的信息还没send完.因此,此时 ...
- Tencent 的电话面试
Tencent的实习生招聘投了简历.然后,万万没想到昨晚腾讯IEG直接给我电话了.当时就惊呆了,我都没有找人内推,就直接电话面试了. 就为昨晚的电话面试写写感想吧!问的挺多的,基本上简历上写了的都问到 ...
- spring_150805_datasource
实体类: package com.spring.model; public class DogPet { private int id; private String name; private in ...