HDU 4405 Aeroplane chess
来源:互联网 发布:校园寝室网络设计方案 编辑:程序博客网 时间:2024/06/05 06:53
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405
题意:一个人在玩飞行棋,一共有n个点和m条航线,每一条航线有x,y,如果到达点x那么会直接到达点y(x<y),初始在1,当坐标大于等于n时游戏结束。每一步会投一个六面骰子来决定移动步数,求游戏结束的期望投掷次数。
思路:f[i]表示在i点时游戏结束的期望次数。f[i] = 1 / 6( ∑f[i+j] ) + 1 (1<=j<=6) 或者 f[i] = f[ pos[i] ] i->pos[i]是一条航线。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define rep(i,j,k) for(int i=j; i<=k; i++)#define Clean(x,y) memset(x,y,sizeof(x))const int maxn=100009;int aim[maxn];bool flag[maxn];double f[maxn];int n,m;int main(){ while(cin>>n>>m) { if(m+n==0) break; Clean(f,0); Clean(flag,false); Clean(aim,0); int x,y; rep(i,1,m) { scanf("%d %d",&x,&y); flag[x]=true; aim[x]=y; } rep(i,1,n) { int temp=aim[i]; while(aim[temp]) temp=aim[temp]; aim[i]=temp; } f[n]=0; for(int i=n-1;i>=0;i--) { if (flag[i]) f[i] = f[ aim[i] ]; else f[i]=(f[i+1]+f[i+2]+f[i+3]+f[i+4]+f[i+5]+f[i+6])/6+1; } printf("%0.4f\n",f[0]); } return 0;}
0 0
- hdu 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- HDU 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- HDU 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- HDU 4405 Aeroplane chess
- HDU 4405 Aeroplane chess
- HDU 4405Aeroplane chess
- HDU 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- hdu #4405:Aeroplane chess
- HDU 4405 Aeroplane chess
- HDU 4405 Aeroplane chess
- HDU 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- java中的CountDownLatch
- NodeJS学习三之API
- 300. Longest Increasing Subsequence(C++实现)
- 国标28181sip开源库介绍(陆续补充完备)
- MySQL日期查询:本周、本月、本季、本年
- HDU 4405 Aeroplane chess
- STL中的set与multiset
- 1.1 Python简介
- The JSP specification requires that an attribute name is preceded by whitespace
- hdu 3065 病毒侵袭持续中
- Node.js简单介绍
- IE中的ActiveXObject对象-基础
- Linux字符设备驱动结构
- ios时间戳与时间的转换