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

    什么是Servlet Servlet 为创建基于 web 的应用程序提供了基于组件.独立于平台的方法,可以不受 CGI 程序的性能限制.Servlet 有权限访问所有的 Java API,包括访问企业 ...

  2. Ubuntu-14.04-QT开发环境搭建-(一)

    Ubuntu 14.04 QT 开发环境搭建 一 . 软件:qt-creator-linux-x86-opensource-2.7.0.binqt-everywhere-opensource-src- ...

  3. nginx config的多个config配置

    在我们的一台服务器上,一个nginx服务器下面可能跑着许多许多的项目; 那么就需要配置多个对应的配置 端口号 已经文件入库目录等等 那么项目多了以后,把这些项目都写到一个文件里 到后期难以查看与管理 ...

  4. 【转】java接口的性能测试

    这周尝试了一把性能测试,之前都是测试网站的性能测试,java接口的性能测试还是头一次,学到了很多,特此分享一下. 主要用到了两个性能测试工具,一个是jmeter,一个是LoadRunner. 使用jm ...

  5. java代码,输入n多个数,求其平均值,虽有重复,但是第二次,我就乱写了

    总结:对象调用方法,与在main 里直接输出没什么大的区别,少用方法, 乱搞++++ package com.c2; import java.util.Scanner; public class DD ...

  6. 网络编程Socket之wireshark使用

    这里只对wireshark进行简单的使用介绍.里面的报表,IO图形分析等以后再谈....  这里不提供下载地址了,不是什么稀有资源,我使用的wireshark是在百度软件中心下载的. 第一步:选择需要 ...

  7. elasticsearch pinyin 拼音分词器

    安装pinyin分词 地址:https://github.com/medcl/elasticsearch-analysis-pinyin PUT py_test { "index" ...

  8. PHP中的use、命名空间的理解

    看.Net中的命名空间和using using Ddd.Core; using Ddd.Core.Caching; using Ddd.Core.Data; using Ddd.Core.Domain ...

  9. leetcode876

    class Solution { public: ListNode* middleNode(ListNode* head) { if (head == NULL) { return nullptr; ...

  10. LCS(详解)

    一,问题描述 给定两个字符串,求解这两个字符串的最长公共子序列(Longest Common Sequence).比如字符串1:BDCABA:字符串2:ABCBDAB 则这两个字符串的最长公共子序列长 ...