题意:在一个三维的空间,每个点都有一盏灯,开始全是关的.现在每次随机选两个点,把两个点之间的全部点,开关都按一遍,问k次过后开着的灯的期望数量;

析:很容易知道,如果一盏灯被按了奇数次,那么它肯定是开的,否则就是关的,所以我们只要计算每盏灯开着的概率就好了。对于每盏灯,假设开一次的概率是p, 这个很容易求得,那么开一共k次有奇数次开着的和是多少呢?假设Fn表示n次奇数的和,那么Fn = Fn * (1-p) + (1-Fn)*p,然后就好算了。解得Fn = 0.5 - 0.5*(1-2p)^n。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 100000 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} double solve(int i, int j){
return (2.0 * i * (j-i+1.0) - 1.0) / j / j;
} int main(){
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
double ans = 0.0;
int x, y, z;
scanf("%d %d %d %d", &x, &y, &z, &n);
for(int i = 1; i <= x; ++i) for(int j = 1; j <= y; ++j)
for(int k = 1; k <= z; ++k){
double p = solve(i, x) * solve(j, y) * solve(k, z);
ans += 0.5 - 0.5 * pow(1-2*p, n);
}
printf("Case %d: %.10f\n", kase, ans);
}
return 0;
}

  

LightOJ 1284 Lights inside 3D Grid (数学期望)的更多相关文章

  1. LightOJ 1284 - Lights inside 3D Grid 概率/期望/二项式定理

    题意:给你一个长宽高为x,y,z的长方体,里面每个格子放了灯,再给你k次选取任意长方体形状的区块,对其内所有灯开或关操作,初始为关,问亮灯数量的期望值. 题解:首先考虑选取区块的概率,使某个灯在被选取 ...

  2. LightOJ - 1284 Lights inside 3D Grid —— 期望

    题目链接:https://vjudge.net/problem/LightOJ-1284 1284 - Lights inside 3D Grid    PDF (English) Statistic ...

  3. LightOJ - 1284 Lights inside 3D Grid (概率计算)

    题面: You are given a 3D grid, which has dimensions X, Y and Z. Each of the X x Y x Z cells contains a ...

  4. 【非原创】LightOJ - 1284 Lights inside 3D Grid【概率期望】

    学习博客: 戳这里 戳这里 戳这里 戳这里 题意: 在一个三维的空间,每个点都有一盏灯,开始全是关的, 现在每次随机选两个点,把两个点之间的全部点,开关都按一遍:问k次过后开着的灯的期望数量: 题解: ...

  5. Lights inside 3D Grid LightOJ - 1284 (概率dp + 推导)

    Lights inside 3D Grid LightOJ - 1284 题意: 在一个三维的空间,每个点都有一盏灯,开始全是关的, 现在每次随机选两个点,把两个点之间的全部点,开关都按一遍:问k次过 ...

  6. LightOJ1284 Lights inside 3D Grid (概率DP)

    You are given a 3D grid, which has dimensions X, Y and Z. Each of the X x Y x Z cells contains a lig ...

  7. LightOj_1284 Lights inside 3D Grid

    题目链接 题意: 给一个X * Y * Z 的立方体, 每个单位立方体内都有一盏灯, 初始状态是灭的, 你每次操作如下: 1)选择一个点(x1, y1, z1)     再选择一个点(x2, y2, ...

  8. LightOj 1030 - Discovering Gold(dp+数学期望)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 题意:在一个1*n 的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得 ...

  9. uva 11605 - Lights inside a 3d Grid(概率)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=2652" style=""& ...

随机推荐

  1. 本地连接远程环境mysql报错:Host'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server

    问题现象:本机连接远程环境的mysql数据库报错,提示本机ip无法连接到mysql服务器. 问题原因:本机对远程mysql数据库没有访问权限. 解决方法:在远程mysql数据库添加本机ip的访问权限: ...

  2. STM32高级定时器用于普通定时,定时周期变长

    最近在用stm32定时器控制步进电机,由于普通定时器不够用,只能把TIM1当普通定时器用,我随手就把普通定时器的代码搬过去. void cs_Timer_Init(void) //TIM1 us级 { ...

  3. Unidac手工安装

      Universal Data Access Components Source Code Copyright 1997-2010, Devart. All Rights ReservedThere ...

  4. Delphi2010中DataSnap高级技术(转)

    一. 为DataSnap系统服务程序添加描述 这几天一直在研究Delphi 2010的DataSnap,感觉功能真是很强大,现在足有理由证明Delphi7该下岗了. DataSnap有三种服务模式,其 ...

  5. python urllib和urllib3包

    urllib.request urllib当中使用最多的模块,涉及请求,响应,浏览器模拟,代理,cookie等功能. 1. 快速请求 urlopen返回对象提供一些基本方法: read 返回文本数据 ...

  6. python 安装相关命令-汇总

    Microsoft Windows [版本 10.0.14393] (c) 2016 Microsoft Corporation.保留所有权利. C:\Windows\system32>pyth ...

  7. DoDataExchange函数,UpdateData(TRUE)和UpdateData(FALSE)的区别

    MFC控件(暂时为Edit控件)与数据的绑定,变量值可以在界面和后台之间传递. 我们在DoDataExchange(CDataExchange* pDX) 函数里,实现了MFC控件和变量的绑定.  若 ...

  8. mybatis~SQL映射

    student.xml里面是这么写的: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE m ...

  9. php文件上传总结

    前言: 学习php中 1.表单代码: <html> <head> <title>文件上传</title> </head> <body ...

  10. day3心得

    1. 集合 主要作用: 去重 关系测试, 交集\差集\并集\反向(对称)差集 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 >>&g ...