hdu 4405 Aeroplane chess
来源:互联网 发布:月野里沙数据 编辑:程序博客网 时间:2024/05/16 03:18
题解:
递推题+并查集
用小数据分析一下,可以看出有递推式:
e[find(i+1)]=(e[i]+p[i])/6.0;
p[find(i+1)=p[i]]/6.0;
find(i+1)是i可以走的一个点,如果是跳跃点的话跳跃到最后。
#include<iostream>#include<cstring>#include<cstdio>using namespace std;const int maxn=100010;int f[maxn];double e[maxn],p[maxn];int find(int x){ return f[x]==x?x:f[x]=find(f[x]);}int main(){ int n,m; while(scanf("%d%d",&n,&m),n+m) { for(int i=0;i<=n+5;i++) f[i]=i; for(int i=1;i<=m;i++) { int x,y; scanf("%d%d",&x,&y); f[find(x)]=y; } memset(e,0,sizeof(e)); memset(p,0,sizeof(p)); p[0]=1; for(int i=0;i<n;i++) for(int j=1;j<=6;j++) { int temp=find(i+j); e[temp]+=(e[i]+p[i])/6.0; p[temp]+=p[i]/6.0; } double ans=0; for(int i=0;i<=5;i++) ans+=e[n+i]; printf("%.4f\n",ans); } return 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
- 判断链表中是否有环
- pku1029-False coin
- 呵呵,人心里的两个小孩
- PL/SQL专家指南2——PL/SQL精髓
- VS2010帮助文档和安装
- hdu 4405 Aeroplane chess
- 原码,补码,反码
- static
- 关于Visual Studio、VC和C++的那些事
- VIM配置成开发工具
- 二叉树的高度和节点数
- Spring事务配置方法介绍
- MySQL下实现不区分大小写
- 求矩形交集的面积