题意:在一个三维的空间,每个点都有一盏灯,开始全是关的.现在每次随机选两个点,把两个点之间的全部点,开关都按一遍,问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. Elasticsearch聚合优化 | 聚合速度提升5倍

    https://blog.csdn.net/laoyang360/article/details/79253294 1.聚合为什么慢?大多数时候对单个字段的聚合查询还是非常快的, 但是当需要同时聚合多 ...

  2. ubuntu 设置固定DNS

    1.打开 xxx@ubuntu:~$ sudo vim /etc/resolvconf/resolv.conf.d/base 2.输入以下DNS,保存退出. nameserver 8.8.8.8 na ...

  3. MSSQL使用sqlbulkcopy批量插入数据

    具体代码如下: /// <summary> /// 批量插入数据到BayonetZipFailedPic表 /// </summary> /// <param name= ...

  4. 88EE1111 PHY芯片设置

    本次调试88EE1111 PHY芯片之主要目的主要对应为了将其默认的GMII接口通过配置成RGMII接口.因此,可能本文档涉及到的内容并没有涉及到PHY芯片的88EE1111所有内容. PHY芯片管理 ...

  5. linux 混杂设备驱动之adc驱动

    linux2.6.30.4中,系统已经自带有了ADC通用驱动文件---arch/arm/plat-s3c24xx/adc.c,它是以平台驱动设备模型的架构来编写的,里面是一些比较通用稳定的代码,但是l ...

  6. 进程句柄和进程ID的区别和关系

    进程和进程句柄和进程id含义 进程是一个正在运行的程序,进程里可以包括多个模块(DLL,OCX,等)进程句柄是程序访问时用到的东西,当前进程句柄等于主模块的句柄,当你使用OpenProcess时的进程 ...

  7. 深度剖析collections模块

    namedtuple OrderedDict deque tuple defaultdict Counter ChainMap

  8. SSD惊悚的跪了,找回数据

    1.电脑出现小bug,例如显示乱码,开机变慢等,都是SSD跪的前兆,哭,我怎么就没看出来,而且没有备份过数据. 2.终于,PC死机了...OK,重启,纳尼?起不来... 3.大哭,所有代码,所有论文不 ...

  9. nat123软件windows版

    转自:http://www.nat123.com/pages_8_565.jsp 同时支持内网和公网IP.只要可以上网,即可将所有应用发布外网. >>nat123客户端windows版本软 ...

  10. 微信小程序中在页面中实现下拉刷新显示提醒语后在消失

    最近在做小程序的时候遇见一个问题,就是页面要下拉刷新给客户一个提醒语,查看了小程序的官方文档 这里有个注意点:如果你是一页进行下拉刷新就在那个文件夹的json里面加上"enablePullD ...