ZOJ2271 Chance to Encounter a Girl
来源:互联网 发布:数据分析公司统计学 编辑:程序博客网 时间:2024/06/07 02:00
入门级DP题,最重要就是每天更新每个格子的小女孩出现的概率,同时累加年轻人所在格子的小女孩出现的概率后清零
/******************************************************************************* # Author : Neo Fung # Email : neosfung@gmail.com # Last modified: 2011-12-30 19:19 # Filename: ZOJ2271 Chance to Encounter a Girl.cpp # Description : ******************************************************************************/// #include "stdafx.h"// #define DEBUG#include <fstream>#include <stdio.h>#include <iostream>#include <string.h>#include <string>#include <memory.h>#include <limits.h>#include <algorithm>#include <math.h>#include <numeric>#include <functional>#include <ctype.h>#defineMAX 120using namespace std;double dp[MAX][MAX],pre[MAX][MAX];int check(const int &x,const int &y,const int &n){int ans=0;if(x+1<n)++ans;if(x>0)++ans;if(y+1<n)++ans;if(y>0)++ans;return ans;}void travel(const int &n){memset(dp,0.0,sizeof(dp));for(int i=0;i<n;++i)for(int j=0;j<n;++j)if(pre[i][j]>0.0){double temp=pre[i][j]/check(i,j,n);if(i+1<n)dp[i+1][j]+=temp;if(i>0)dp[i-1][j]+=temp;if(j+1<n)dp[i][j+1]+=temp;if(j>0)dp[i][j-1]+=temp;}memcpy(pre,dp,sizeof(dp));}int main(void){#ifdef DEBUG freopen("C:/Users/neo/Desktop/stdin.txt","r",stdin); freopen("C:/Users/neo/Desktop/stdout.txt","w",stdout); #endif int n;while(~scanf("%d",&n)){memset(pre,0.0,sizeof(pre));pre[n/2][n/2]=1;double ans=0.0;for(int i=0;i<n;++i){travel(n);ans+=pre[i][n/2];pre[i][n/2]=0.0;}printf("%.4lf\n",ans);} return 0;}
- ZOJ2271 Chance to Encounter a Girl
- zoj 2271 Chance to Encounter a Girl
- zoj 2271 - 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
- html表格标记
- SQLSERVER2005的ROW_NUMBER具体使用[转]
- 操作Android 手机通讯录数据库
- jQuery设计思想
- innoDb 的多线程并发调优
- ZOJ2271 Chance to Encounter a Girl
- cookie原理及作用
- Google 语法
- typedef和define具体的详细区别
- C#正则表达式整理备忘
- oracle 用户频繁被锁
- 接口的好处
- Linux操作系统下配置多线路ADSL
- maven3学习笔记1--maven的安装与配置