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

option=com_onlinejudge&Itemid=8&page=show_problem&problem=2652" style="">题目链接:uva 11605 - Lights inside a 3d Grid

题目大意:给定一个三维坐标系大小,每一个位置有一个灯。初始状态为关。每次随机选中两个点,以这两点为对角线的长方体内全部灯转变状态。操作K次。问说平均情况下。最后会有多少栈灯亮着。

解题思路:枚举坐标系上的点。计算单个点亮着的概率,然后累加即使总体的期望。

对于一个点x,y,z,分别考虑每维坐标系,比如x。选中的概率为px=2?(n?x+1)?x?1n?n,三维坐标均选中的概率p即为该点被选中的概率。

可是对于一点来说,由于操作K次,所以最后灯为亮的话。操作到灯的次数一定要为奇数才行,所以有∑C(iK)pi(1?p)K?i(i为奇数)

===》(1?p+p)K?(1?p?p)K2

===》1?(1?2p)K2

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int N, M, P, K;

inline double getp (double n, double x) {
    double s = n * n;
    double t = 2 * (n - x + 1) * x - 1;
    return t / s;
}

inline double handle (double p) {
    return (1 - pow(1 - 2 * p, K)) / 2;
}

double solve () {
    double ret = 0;
    for (int x = 1; x <= N; x++) {
        double px = getp(N, x);
        for (int y = 1; y <= M; y++) {
            double py = getp(M, y);
            for (int z = 1; z <= P; z++) {
                double pz = getp(P, z);
                ret += handle(px * py * pz);
            }
        }
    }
    return ret;
}

int main () {
    int cas;
    scanf("%d", &cas);
    for (int kcas = 1; kcas <= cas; kcas++) {
        scanf("%d%d%d%d", &N, &M, &P, &K);
        printf("Case %d: %.10lf\n", kcas, solve());
    }
    return 0;
}
时间: 2024-08-02 07:02:00

uva 11605 - Lights inside a 3d Grid(概率)的相关文章

UVA 11605 - Lights inside a 3d Grid(概率+数学)

UVA 11605 - Lights inside a 3d Grid 题目链接 题意:给定一个NxMxP的三维网格,每个格子上一盏灯,现在每次随机选择两点,把这两点构成立方体中间那一块开关灯状态转换,问K步之后网格中亮灯的期望 思路:概率问题,把x,y,z轴分开考虑,算出每一个点xi,yi,zi分别能被选到的情况数,然后根据乘法原理相乘起来除以总情况就能算出一点的概率,然后问题就是K次了,对于K次,每次开到的概率为P的情况下,总情况为∑k1Pi(1?P)k?ii为奇数,那么根据组合公式很容易化

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 light. Initially all lights are off. You will have K turns. In each of the K turns, You select a cell A randomly from the grid, You select a cell B rando

3D Grid Effect – 使用 CSS3 制作网格动画效果

今天我们想与大家分享一个小的动画概念.这个梦幻般的效果是在马库斯·埃克特的原型应用程序里发现的??.实现的基本思路是对网格项目进行 3D 旋转,扩展成全屏,并呈现内容.我们试图模仿应用程序的行为,因此创建了两个演示,分别演示垂直和水平旋转网格项. 温馨提示:为保证最佳的效果,请在 IE10+.Chrome.Firefox 和 Safari 等现代浏览器中浏览. 您可能感兴趣的相关文章 创意无限!一组网页边栏过渡动画[附源码下载] 真是好东西!13种非常动感的页面加载动画效果 你见过吗?9款超炫的

LightOJ 1284 Lights inside 3D Grid

题意是给出一个由边长为1的立方体组成的长方体,每个小立方体中有一盏灯,每次操作随机选择两个立方体,以这两个立方体作为对角线顶点确定一个长方体,长方体中所有块的灯自己取反,就是亮着的关上,暗着的打开,求这样操作k次以后亮着的灯数的期望值. 设F(i)为操作i次以后对某灯奇数次取反的概率,G(i)为偶数次,奇数次取反以后灯是亮着的,贡献的期望值显然是1,所以求出F(k)就可以了. 设p为某灯被选择到的概率. 显然F(i) = F(i - 1) * (1 - p) + G(i - 1) * p, G(

UVA 11427 Expect the Expected(DP+概率)

链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 [思路] DP+概率 见白书. [代码] 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 5 const int N = 100+10; 6 7 int n,a,b; 8 double f[N][N]; 9 10 int main() { 11 int T,kase=

UVA - 11427 Expect the Expected (DP+概率)

Description Problem A Expect the Expected Input: Standard Input Output: Standard Output   Some mathematicalbackground. This problem asks you to compute the expected value of arandom variable. If you haven't seen those before, the simple definitions a

UVA - 11762 - Race to 1 记忆化概率

Dilu have learned a new thing about integers, which is - any positive integer greater than 1 can bedivided by at least one prime number less than or equal to that number. So, he is now playing withthis property. He selects a number N. And he calls th

UVA 12446 How Many... in 3D! 搭积木 dp

题目链接:点击打开链接 题意: 用1*1*2的方块搭出2*2*N的方块的方法数 则对于每一层有9种状态 0.全为1. 1. 00 __ 0表示这个为空,__表示这两个平躺着一个方块 2. 00 11 0表示这格为空,1表示这格方块是直立放着的. 如此类推除第0种共8种状态,然后就是简单的转移. 而其他状态是无效的,不会参与到答案的计算中,所以不需要考虑 #include <string> #include <iostream> #include <cstdio> #in

UVA 11600-Masud Rana(状压,概率dp)

题意: 有n个节点的图,开始有一些边存在,现在每天任意选择两点连一条边(可能已经连过),求使整个图联通的期望天数. 分析: 由于开始图可以看做几个连通分量,想到了以前做的一个题,一个点代表一个集合(这里是连通分量)进行压缩 dp[i][s]表示最后连接的第i个联通分量,联通状态是s时的期望天数,dp[0][1],即为答案,由于s可能很大,用记忆化搜索 #include <map> #include <set> #include <list> #include <c