zoj 2271 - Chance to Encounter a Girl

题目:平面图上有一个女孩,她初始在(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;
}
时间: 2024-08-04 14:47:33

zoj 2271 - Chance to Encounter a Girl的相关文章

图论 500题——主要为hdu/poj/zoj

转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i

ZOJ 3233 Lucky Number

Lucky Number Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: 323364-bit integer IO format: %lld      Java class name: Main Watashi loves M mm very much. One day, M mm gives Watashi a chance to choose a number

ZOJ 3671 Japanese Mahjong III

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3671 Japanese Mahjong III Time Limit: 2 Seconds      Memory Limit: 65536 KB Mahjong is a game of skill, strategy and calculation and involves a certain degree of chance. In this proble

[dp] zoj 3740 Water Level

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5122 Water Level Time Limit: 2 Seconds      Memory Limit: 65536 KB Hangzhou is a beautiful city, especially the West Lake. Recently, the water level of the West Lake got lower and lower

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

zoj 2156 - Charlie&#39;s Change

题目:钱数拼凑,面值为1,5,10,25,求组成n面值的最大钱币数. 分析:dp,01背包.需要进行二进制拆分,否则TLE,利用数组记录每种硬币的个数,方便更新. 写了一个 多重背包的 O(NV)反而没有拆分快.囧,最后利用了状态压缩优化 90ms: 把 1 cents 的最后处理,其他都除以5,状态就少了5倍了. 说明:貌似我的比大黄的快.(2011-09-26 12:49). #include <stdio.h> #include <stdlib.h> #include <

ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 最小生成树 Kruskal算法

题目链接:ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 Building a Space Station Time Limit: 2 Seconds      Memory Limit: 65536 KB You are a member of the space station engineering team, and are assigned a task in the construction process of the statio

ZOJ 3607 Lazier Salesgirl (贪心)

Lazier Salesgirl Time Limit: 2 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy

ZOJ - 2243 - Binary Search Heap Construction

先上题目: Binary Search Heap Construction Time Limit: 5 Seconds      Memory Limit: 32768 KB Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal n