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 randomly from the grid and
- Toggle the states of all the bulbs bounded by cell A and cell B, i.e. make all the ON lights OFF and make all the OFF lights ON which are bounded by A and B. To be clear, consider cell A is (x1, y1, z1) and cell B is (x2, y2, z2). Then you have to toggle all the bulbs in grid cell (x, y, z) where min(x1, x2) ≤ x ≤ max(x1, x2), min(y1, y2) ≤ y ≤ max(y1, y2) and min(z1, z2) ≤ z ≤ max(z1, z2).
Your task is to find the expected number of lights to be ON after K turns.
Input
Input starts with an integer T (≤ 50), denoting the number of test cases.
Each case starts with a line containing four integers X, Y, Z (1 ≤ X, Y, Z ≤ 100) and K (0 ≤ K ≤ 10000).
Output
For each case, print the case number and the expected number of lights that are ON after K turns. Errors less than 10-6will be ignored.
Sample Input
5
1 2 3 5
1 1 1 1
1 2 3 0
2 3 4 1
2 3 4 2
Sample Output
Case 1: 2.9998713992
Case 2: 1
Case 3: 0
Case 4: 6.375
Case 5: 9.09765625
题解:


参考代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int T,X,Y,Z,K;
double ans; double calc(int x,int m)
{
return 1.0-1.0*((m-x)*(m-x)+(x-)*(x-))/(m*m);
} int main()
{
scanf("%d",&T);
for(int cas=;cas<=T;++cas)
{
ans=;
scanf("%d%d%d%d",&X,&Y,&Z,&K);
for(int i=;i<=X;++i)
for(int j=;j<=Y;++j)
for(int k=;k<=Z;++k)
{
double p=calc(i,X)*calc(j,Y)*calc(k,Z);
ans+=0.5-0.5*pow(1.0-*p,K);
}
printf("Case %d: %.8lf\n",cas,ans);
} return ;
}
LightOJ1284 Lights inside 3D Grid (概率DP)的更多相关文章
- LightOJ 1284 - Lights inside 3D Grid 概率/期望/二项式定理
题意:给你一个长宽高为x,y,z的长方体,里面每个格子放了灯,再给你k次选取任意长方体形状的区块,对其内所有灯开或关操作,初始为关,问亮灯数量的期望值. 题解:首先考虑选取区块的概率,使某个灯在被选取 ...
- Lights inside 3D Grid LightOJ - 1284 (概率dp + 推导)
Lights inside 3D Grid LightOJ - 1284 题意: 在一个三维的空间,每个点都有一盏灯,开始全是关的, 现在每次随机选两个点,把两个点之间的全部点,开关都按一遍:问k次过 ...
- LightOJ - 1284 Lights inside 3D Grid —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1284 1284 - Lights inside 3D Grid PDF (English) Statistic ...
- 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 ...
- 【非原创】LightOJ - 1284 Lights inside 3D Grid【概率期望】
学习博客: 戳这里 戳这里 戳这里 戳这里 题意: 在一个三维的空间,每个点都有一盏灯,开始全是关的, 现在每次随机选两个点,把两个点之间的全部点,开关都按一遍:问k次过后开着的灯的期望数量: 题解: ...
- LightOj_1284 Lights inside 3D Grid
题目链接 题意: 给一个X * Y * Z 的立方体, 每个单位立方体内都有一盏灯, 初始状态是灭的, 你每次操作如下: 1)选择一个点(x1, y1, z1) 再选择一个点(x2, y2, ...
- LightOJ 1284 Lights inside 3D Grid (数学期望)
题意:在一个三维的空间,每个点都有一盏灯,开始全是关的.现在每次随机选两个点,把两个点之间的全部点,开关都按一遍,问k次过后开着的灯的期望数量: 析:很容易知道,如果一盏灯被按了奇数次,那么它肯定是开 ...
- uva 11605 - Lights inside a 3d Grid(概率)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=2652" style=""& ...
- HDU 4050 wolf5x(动态规划-概率DP)
wolf5x Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
随机推荐
- Linux命令实战(二)
1.printf格式化输出(format and print data) 语法:printf(选项)(参数) 参数 输出格式:指定数据输出时的格式: 输出字符串:指定要输出的数据. 格式替代符 %c ...
- 微信小程序引入全局或公共样式
在开发的过程中,总会遇到很多可复用性的样式,为了代码更加的简洁和减少微不住道的文件体积,我抽取了一部分的公共样式,并全局引入,不知是否妥当,如有更好的想法,欢迎一起探讨 在app.wxss中引入 然后 ...
- 微擎 pdo_fetchall() 函数
微擎 pdo_fetchall() 函数 注意点: 该函数内部直接执行原生 SQL 语句 如果在传递表名的时候使用了 tablename .则不加 ims_ 前缀 参数的传递通过 :param 的形式 ...
- nyoj 66-分数拆分 (Java,暴力)
66-分数拆分 内存限制:64MB 时间限制:3000ms 特判: No 通过数:7 提交数:9 难度:1 题目描述: 现在输入一个正整数k,找到所有的正整数x>=y,使得1/k=1/x+1/y ...
- .NET Core 获取数据库上下文实例的方法和配置连接字符串
目录 .NET Core 获取数据库上下文实例的方法和配置连接字符串 ASP.NET Core 注入 .NET Core 注入 无签名上下文 OnConfigure 配置 有签名上下文构造函数和自己n ...
- 基于 cobbler 实现自动安装 linux 系统
使用 cobbler 实现自动安装 centos 6.7系统 1.yum install cobbler -y 安装 cobbler ,有依赖关系,会自动把 TFTP .HTTP 服务安装上:cobb ...
- IBM-X3850-4U诊断面板信息
IBM X3850 4U 指示灯 描述 OVERSPEC 没有足够的电量为系统供电.NONRED和LOG指示灯可能也点亮 PS 一个电源故障或者被电源未插 LINK 保留 CPU CPU出现故障.丢失 ...
- proxy protocol
Proxy protocol 是haproxy 作者开发和设计的一个inernet 协议, 用于获取客户端的IP地址. 在使用7层代理是可以向http协议添加X-Forword-For来实现,而4层协 ...
- 2019-11-6:ubuntu安装配置JAVA环境
1,下载JAVA,官方java 18下载网站:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-21331 ...
- Fabric1.4源码解析:Peer节点启动过程
看一下Peer节点的启动过程,通常在Fabric网络中,Peer节点的启动方式有两种,通过Docker容器启动,或者是通过执行命令直接启动. 一般情况下,我们都是执行docker-compose -f ...