zoj 2271 - Chance to Encounter a Girl
来源:互联网 发布:阿里云业务 编辑:程序博客网 时间:2024/05/20 17:41
题目:平面图上有一个女孩,她初始在(n/2,,n/2),每次可以走到上下左右四个格子中的一个,
她每次随机的走的动,你从(-1,n/2)向右移动,问你们相遇的概率。
分析:概率dp。事件为阶段,每个点由上一阶段周围的四个点来维护。
分成角、边、和中间三种计算概率(分别为1/5,1/3,1/4);
关于概率的求解,如果遇到就结束了,所以向后走就说明之前没有碰到,
所以不用前面的碰到的概率计算后面的值;
时间O(N^3*T),在问题的边缘时间,所以打表计算。
说明:(2011-09-19 09:31)。
#include <stdio.h>#include <string.h>double answ[ 51 ] = { 0.0000,0.6667,0.0000,0.4074,0.0000, 0.3361,0.0000,0.2928,0.0000,0.2629, 0.0000,0.2407,0.0000,0.2233,0.0000, 0.2092,0.0000,0.1975,0.0000,0.1875, 0.0000,0.1789,0.0000,0.1714,0.0000, 0.1648,0.0000,0.1589,0.0000,0.1536, 0.0000,0.1487,0.0000,0.1443,0.0000, 0.1403,0.0000,0.1366,0.0000,0.1332, 0.0000,0.1300,0.0000,0.1270,0.0000, 0.1243,0.0000,0.1217,0.0000,0.1192};/*double maps[ 100 ][ 100 ][ 100 ];short dxdy[ 4 ][ 2 ] = {1,0,0,1,-1,0,0,-1};void madelist() // 打表程序 { for ( int n = 1 ; n < 100 ; n += 2 ) { double sum = 0.0; memset( maps, 0, sizeof( maps ) ); maps[ 0 ][ n/2 ][ n/2 ] = 1.0; for ( int t = 0 ; t < n ; ++ t ) for ( int i = 0 ; i < n ; ++ i ) for ( int j = 0 ; j < n ; ++ j ) for ( int k = 0 ; k < 4 ; ++ k ) { int x = i+dxdy[ k ][ 0 ]; int y = j+dxdy[ k ][ 1 ]; if ( x > 0 && x < n-1 && y > 0 && y < n-1 ) maps[ t+1 ][ i ][ j ] += 0.25*maps[ t ][ x ][ y ]; else if ( ( x == 0 && y == 0 ) || ( x == 0 && y == n-1 ) || ( x== n-1 && y == 0 ) || ( x == n-1 && y == n-1 ) ) maps[ t+1 ][ i ][ j ] += 0.5*maps[ t ][ x ][ y ]; else maps[ t+1 ][ i ][ j ] += 1.0/3*maps[ t ][ x ][ y ]; if ( i == n/2 && j == t ) { sum += maps[ t+1 ][ i ][ j ]; maps[ t+1 ][ i ][ j ] = 0.0; } } printf("%.4lf,",sum); }}*/int main(){ int m; while ( ~scanf("%d",&m) ) printf("%.4lf\n",answ[ m/2 ]); return 0;}
0 0
- zoj 2271 Chance to Encounter a Girl
- zoj 2271 - Chance to Encounter a Girl
- ZOJ2271 Chance to Encounter a Girl
- 7 Ways to Defuse a Difficult Encounter
- how to attract a girl
- how to chase a girl
- a girl
- If there's a chance to say I Love you
- A girl called Emma
- I wanna a girl
- a good girl
- God is a girl
- A. Boy or Girl
- A Boy or Girl
- Find a girl friend
- a girl i love
- I'm thankful that、do one thing at once、mainly trade with、chance encounter、direct contact
- Let's take a chance to help disadvantaged children in Vietnam
- LayoutInflater的使用
- 搭建安卓开发环境 用sdk manager下载不了sdk包的解决方法
- 【转载】HttpWebRequest的GetResponse或GetRequestStream偶尔超时 + 总结各种超时死掉的可能和相应的解决办法
- 【Hive】Hive笔记:Hive调优总结——数据倾斜,join表连接优化
- Android ViewPager使用详解
- zoj 2271 - Chance to Encounter a Girl
- spring batch : 在不同steps间传递数据
- C++细节笔记
- HDU 4415 Assassin’s Creed(贪心)
- 杭电acm2024C语言合法标识符
- LeetCode Word Search
- 'make menuconfig' requires the ncurses libraries.
- 常用编码软件简单使用记录 2 : 非自主编码器
- tomcat源码分析学习笔记(五)