HDU-3854 LOOPS
http://acm.hdu.edu.cn/showproblem.php?pid=3853
LOOPS
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 2263 Accepted Submission(s):
911
Girl).
Homura wants to help her friend Madoka save the world. But because
of the plot of the Boss Incubator, she is trapped in a labyrinth called
LOOPS.
The planform of the
LOOPS is a rectangle of R*C grids. There is a portal in each grid except the
exit grid. It costs Homura 2 magic power to use a portal once. The portal in a
grid G(r, c) will send Homura to the grid below G (grid(r+1, c)), the grid on
the right of G (grid(r, c+1)), or even G itself at respective probability (How
evil the Boss Incubator is)!
At the beginning Homura is in the top left
corner of the LOOPS ((1, 1)), and the exit of the labyrinth is in the bottom
right corner ((R, C)). Given the probability of transmissions of each portal,
your task is help poor Homura calculate the EXPECT magic power she need to
escape from the LOOPS.
R, C <= 1000).
The following R lines, each contains C*3 real numbers,
at 2 decimal places. Every three numbers make a group. The first, second and
third number of the cth group of line r represent the probability of
transportation to grid (r, c), grid (r, c+1), grid (r+1, c) of the portal in
grid (r, c) respectively. Two groups of numbers are separated by 4
spaces.
It is ensured that the sum of three numbers in each group is 1,
and the second numbers of the rightmost groups are 0 (as there are no grids on
the right of them) while the third numbers of the downmost groups are 0 (as
there are no grids below them).
You may ignore the last three numbers of
the input data. They are printed just for looking neat.
The answer is
ensured no greater than 1000000.
Terminal at EOF
representing the expect magic power Homura need to escape from the
LOOPS.
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
double e[][];
struct node
{
double p1,p2,p3;
}a[][];
int main()
{
int r,c,i,j;
while(~scanf("%d%d",&r,&c))
{
memset(e,,sizeof(e));
for(i=;i<=r;i++)
for(j=;j<=c;j++)
{
scanf("%lf%lf%lf",&a[i][j].p1,&a[i][j].p2,&a[i][j].p3);
}
e[r][c]=;
for(i=r;i>=;i--)
{
for(j=c;j>=;j--)
{
if(i==r&&j==c)
continue;
if(a[i][j].p1==)
continue;
e[i][j]=double(a[i][j].p2*e[i][j+]+a[i][j].p3*e[i+][j]+)/double(-a[i][j].p1); }
}
printf("%.3lf\n",e[][]);
}
return ;
}
HDU-3854 LOOPS的更多相关文章
- HDU 3853 LOOPS 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Time Limit: 15000/5000 MS (Java/Others)Me ...
- hdu 3853 LOOPS(概率 dp 期望)
Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help ...
- HDU 3853 LOOPS 概率DP入门
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Sub ...
- HDU 3853 LOOPS:期望dp【网格型】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意: 有一个n*m的网格. 给出在每个格子时:留在原地.向右走一格,向下走一格的概率. 每走一 ...
- hdu 3853 LOOPS (概率dp 逆推求期望)
题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Tota ...
- HDU 3854 Glorious Array(树状数组)
题意:给一些结点,每个结点是黑色或白色,并有一个权值.定义两个结点之间的距离为两个结点之间结点的最小权值当两个结点异色时,否则距离为无穷大.给出两种操作,一种是将某个结点改变颜色,另一个操作是询问当前 ...
- hdu 3853 LOOPS(基础DP求期望)
题目大意 有一个人被困在一个 R*C(2<=R,C<=1000) 的迷宫中,起初他在 (1,1) 这个点,迷宫的出口是 (R,C).在迷宫的每一个格子中,他能花费 2 个魔法值开启传送通道 ...
- hdu 3853 LOOPS 概率DP
简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...
- HDU 3853 LOOPS
题意:对于每一格,都可以往右走,原地不走,往下走,概率分别为a[i],b[i],c[i](每一个格子与其他格子的概率不一定相同).在R*C的棋盘上(输入数据保证不会走出棋盘),求从(0, 0)走到(R ...
- HDU 3853 LOOPS 可能性dp(水
在拐~ #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...
随机推荐
- [时间操作] C#DateFormat时间帮助类 (转载)
点击下载 DateFormat.rar 主要功能如下 返回每月的第一天和最后一天 看下面代码吧 /// <summary> /// 类说明:时间操作类 /// 编 码 人:苏飞 /// 联 ...
- 使用Delphi读取网络上的文本文件,html文件
使用Delphi读取网络上的txt和html文件 可以使用两种方法: 1.下载文件,然后进行读取 下载文件的Delphi代码可以参考: http://www.delphibbs.com/delphib ...
- Object-C 类实现
这篇为Object-C添加方法的后续. 这里我们应该在类的实现(.m)文件中写 #import "Photo.h" @implementation Photo - (NSStrin ...
- Windows+Git+TortoiseGit+COPSSH安装图文教程 转载
准备工作: 1. Git-1.8.1.2-preview20130201.exe 下载地址: https://code.google.com/p/msysgit/downloads/list 2. C ...
- [学习笔记]设计模式之Chain of Responsibility
为方便读者,本文已添加至索引: 设计模式 学习笔记索引 写在前面 最近时间比较紧,所以发文的速度相对较慢了.但是看到园子里有很多朋友对设计模式感兴趣,我感觉很高兴,能够和大家一起学习这些知识. 之前的 ...
- Android 学习手札(三) 视图(View)
在Android 系统红,任何可视化组件都需要从android.view.View类继承.可以使用两种方式创建View对象. · 一种方式是使用XML来配置View的相关属性,然后使用相应的方法来装载 ...
- 【原创】CMD常用命令:解决实际问题
1.查找某一目录下后缀名文某某的所有文件. 命令格式:dir *.mp3 /a -d/b/s >C:\Users\leemo\Desktop\total.txt MP3为文件后缀名.>是命 ...
- VBA开发经验总结之二:灵活运用工作表属性
近期,在帮公司写一个销售管理的工具,高强度的开发激发了我对一些以前既有方式的看法,特将几点开发经验总结在此. 1.将工作表及窗体的公共变量及特征变量写为工作表或窗体的属性.此种方法的优点: ① 采用面 ...
- new Image()的用途
new Image()用途总结: 1.图片预加载 在做游戏时,为了使图片能快打开可以做预加载. 原理:创建image对象,将image对象的src分别指向需加载的图片地址,图片被请 ...
- php运用curl触发后台脚本不超时执行某项任务
运用curl 设置超时,触发后台脚本执行 例如一些需要长时间等待的任务,如创建数据库,下载网络图片等 $ch = curl_init();//$ch资源可以请求多个连接 curl_setopt($ch ...