Aeroplane chess(HDU 4405)
Aeroplane chess
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2060    Accepted Submission(s): 1346
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.
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.
8 3
2 4
4 5
7 8
0 0
2.3441
求期望,逆推。
开始用的递归,结果疯狂爆栈。。。最后改了递推式
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, (a), sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define MAXN 100050
#define eps 1e-5
bool vis[MAXN];
int flight[MAXN];
int m, n;
double d[MAXN];
int main()
{
while(~scanf("%d%d", &n, &m) && (n + m))
{
_cle(flight, -);
_cle(d, 0.0);
int x, y;
for(int i = ; i < m; i++) {
scanf("%d%d", &x, &y);
flight[x] = y;
}
int dt;
for(int i = n - ; i >= ; i--)
for(int j = ; j <= ; j++) {
dt = i + j;
while(flight[dt] > ) dt = flight[dt];
d[i] += (d[dt] + 1.0) / 6.0;
}
printf("%.4lf\n", d[]);
}
return ;
}
Aeroplane chess(HDU 4405)的更多相关文章
- 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 ...
 - War Chess (hdu 3345)
		
http://acm.hdu.edu.cn/showproblem.php?pid=3345 Problem Description War chess is hh's favorite game:I ...
 - HDU - 4405 Aeroplane chess(期望dp)
		
题意:沿着x轴从0走到大于等于N的某处,每一步的步数由骰子(1,2,3,4,5,6)决定,若恰好走到x轴上某飞行路线的起点,则不计入扔骰子数.问从0走到大于等于N的某处的期望的扔骰子次数. 分析: 1 ...
 - 2018.09.01 hdu4405 Aeroplane chess (期望dp)
		
传送门 期望dp简单题啊. 不过感觉题意不太对. 手过了一遍样例发现如果有捷径必须走. 这样的话就简单了啊. 设f[i]" role="presentation" sty ...
 - 2道acm编程题(2014):1.编写一个浏览器输入输出(hdu acm1088);2.encoding(hdu1020)
		
//1088(参考博客:http://blog.csdn.net/libin56842/article/details/8950688)//1.编写一个浏览器输入输出(hdu acm1088)://思 ...
 - 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 求期望)
		
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
 - HDU 4405 Aeroplane chess (概率DP求期望)
		
题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...
 
随机推荐
- eclupse启动报 Failed to load JavaHL Library.错
			
解决办法: window --> preferences --> Team --> SVN --> Client选项选择: SVNKit x.x.x.xxx
 - CUBRID学习笔记 16  元数据支持
			
简化了很多 ,在sqlserver需要用语句实现的功能 接口如下 public DataTable GetDatabases(string[] filters) public DataTable Ge ...
 - CUBRID学习笔记 7  ms常见错误
			
基本不是权限问题,就是dll问题. 重新下载或应用dll注意版本. 权限的问题,先本机测试. 看看在web管理有无问题. 剩下的基本就简单了 欢迎转载 ,转载时请保留作者信息.本文版权归本人所有, ...
 - Python-爬虫初学
			
#爬取网站中的图片 1 import re #正则表达式库 import urllib #url链接库 def getHtml(url): page = urllib.urlopen(url) #打开 ...
 - Linux Shell脚本攻略 读书笔记
			
Linux Shell脚本攻略 读书笔记 这是一本小书,总共253页,但内容却很丰富,书中的示例小巧而实用,对我这样总是在shell门前徘徊的人来说真是如获至宝:最有价值的当属文本处理,对这块我单独整 ...
 - 模仿$.Callbacks实现
			
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
 - 小型网站如何防范DDoS攻击
			
ddos(Distributed Denial of Service,分布式拒绝服务攻击),俗称洪水攻击.是在传统的DoS攻击基础之上产生的新的破坏力更强的攻击方式.分布式拒绝服务攻击是指借助于客户/ ...
 - iOS - MPMoviePlayer      视频播放
			
前言 MP_EXTERN_CLASS_AVAILABLE(3_2) NS_DEPRECATED_IOS(3_2, 9_0, "Use AVPlayerViewController in AV ...
 - iOS - Notification		通知
			
1.Notification 通知中心实际上是在程序内部提供了消息广播的一种机制,它允许我们在低程度耦合的情况下,满足控制器与一个任意的对象进行通信的目的.每一个 iOS 程序(即每一个进程)都有一个 ...
 - [转载] 【每周推荐阅读】C-Store:列式存储数据库
			
Record-based与column-based是数据库和存储系统里面两种不同的data layout.我们的思维逻辑是基于行记录的,即Record-based data layout,数据记录都是 ...