题意:在一个三维的空间,每个点都有一盏灯,开始全是关的.现在每次随机选两个点,把两个点之间的全部点,开关都按一遍,问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. Toolbar使用

    原文地址 http://www.cnblogs.com/Dentist/p/4370176.html Android4.0出现的Actionbar提供了同意方便的导航管理.很大程度的统一了Androi ...

  2. 程序4-3 umask函数实例

    //http://blog.chinaunix.net/uid-24549279-id-71355.html /* ========================================== ...

  3. unidac 执行Execute后取得受影响行数。

    unidac 执行Execute后取得受影响行数. uniQuery2.SQL.Text := mmo2.Text; uniQuery2.Execute; mmo1.Lines.Add(Format( ...

  4. ubuntu下安装ros出现“无法下载-package.ros.org中某个包-校验和不符”的解决方法

    新安装的Ubuntu14.04,为了科研马上准备装ros indigo,却困难重重,一步一个坎. 比如说按照ros wiki里面一步一步来,当运行sudoapt-get update 然后出现下列情况 ...

  5. NIOS EDS最容易出错的地方

    越来越多的人使用NIOS II.毕竟,NIOS II是世界上功能最多的软核处理器. NIOS EDS通常是在装QUARTUS的时候一起装上的.通常我们在用的时候都是以模板建立工程的. 在很多情况下,我 ...

  6. java里监听相关ActionListene的理解。========此代码是错误的,

    package com.aa; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event. ...

  7. Vue.js:目标结构

    ylbtech-Vue.js:目标结构 1.返回顶部 1. Vue.js 目录结构 上一章节中我们使用了 npm 安装项目,我们在 IDE(Eclipse.Atom等) 中打开该目录,结构如下所示: ...

  8. Windows Media Player 打不开怎么办

    1. 右键VS工具箱的空白处; 2. 打开工具箱, 选择com组件→找到windows media player 3. 如果这里没有发现 windows Media Player怎么办? , 以win ...

  9. java成神之——注释修饰符

    注释修饰符 自定义注释 元注释 通过反射在runtime访问注释 内置注释 多注释实例 错误写法 使用容器改写 使用@Repeatable元注释 注释继承 使用反射获取注释 获取类的注释 获取方法的注 ...

  10. 一个电脑同时运行 64bit 和 32bit 的eclipse 如何匹配 jdk环境

    一个电脑同时运行 64bit 和 32bit   的  eclipse 如何匹配 jdk环境 1 eclipse 分 64bit 和 32bit 两种.  64bit的eclipse 只能搭配 64b ...