LightOJ - 1284 Lights inside 3D Grid —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1284
Time Limit: 4 second(s) | Memory Limit: 32 MB |
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-6 will be ignored.
Sample Input |
Output for Sample Input |
5 1 2 3 5 1 1 1 1 1 2 3 0 2 3 4 1 2 3 4 2 |
Case 1: 2.9998713992 Case 2: 1 Case 3: 0 Case 4: 6.375 Case 5: 9.09765625 |
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e5+; double Get(int pos, int n)
{
return 1.0 - 1.0*((pos-)*(pos-)+(n-pos)*(n-pos))/(n*n);
} double qpow(double x, int y)
{
double s = ;
while(y)
{
if(y&) s *= x;
x *= x;
y >>= ;
}
return s;
} int main()
{
int T, x, y, z, k, kase = ;
scanf("%d", &T);
while(T--)
{
double ans = ;
scanf("%d%d%d%d", &x,&y,&z,&k);
for(int i = ; i<=x; i++)
for(int j = ; j<=y; j++)
for(int t = ; t<=z; t++)
{
double p = Get(i,x)*Get(j,y)*Get(t,z);
ans += 0.5-0.5*qpow(-*p, k);
}
printf("Case %d: %.10lf\n", ++kase, ans);
}
}
LightOJ - 1284 Lights inside 3D Grid —— 期望的更多相关文章
- 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【概率期望】
学习博客: 戳这里 戳这里 戳这里 戳这里 题意: 在一个三维的空间,每个点都有一盏灯,开始全是关的, 现在每次随机选两个点,把两个点之间的全部点,开关都按一遍:问k次过后开着的灯的期望数量: 题解: ...
- LightOJ 1284 - Lights inside 3D Grid 概率/期望/二项式定理
题意:给你一个长宽高为x,y,z的长方体,里面每个格子放了灯,再给你k次选取任意长方体形状的区块,对其内所有灯开或关操作,初始为关,问亮灯数量的期望值. 题解:首先考虑选取区块的概率,使某个灯在被选取 ...
- Lights inside 3D Grid LightOJ - 1284 (概率dp + 推导)
Lights inside 3D Grid LightOJ - 1284 题意: 在一个三维的空间,每个点都有一盏灯,开始全是关的, 现在每次随机选两个点,把两个点之间的全部点,开关都按一遍:问k次过 ...
- 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 ...
- LightOj_1284 Lights inside 3D Grid
题目链接 题意: 给一个X * Y * Z 的立方体, 每个单位立方体内都有一盏灯, 初始状态是灭的, 你每次操作如下: 1)选择一个点(x1, y1, z1) 再选择一个点(x2, y2, ...
- uva 11605 - Lights inside a 3d Grid(概率)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=2652" style=""& ...
- 3D Grid Effect – 使用 CSS3 制作网格动画效果
今天我们想与大家分享一个小的动画概念.这个梦幻般的效果是在马库斯·埃克特的原型应用程序里发现的.实现的基本思路是对网格项目进行 3D 旋转,扩展成全屏,并呈现内容.我们试图模仿应用程序的行为,因此 ...
随机推荐
- Could not open lock file/var/lib/dpkg/lock
apt-get时出现错误提示: E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailabl ...
- java调试工具jdb
Finds and fixes bugs in Java platform programs. Synopsis jdb [options] [classname] [arguments] optio ...
- MFC的运行机理分析+ASC码问题
Win32程序是从WinMain开始执行的,但是MFC把WinMain给封装了,不会出现在你的代码里面,他已经编译到mfc80.dll了(VS2005)了. 在MFC中的执行顺序是这样的,首先Wind ...
- 【电子签章】HTML格式合同转化成PDF文件
代码地址如下:http://www.demodashi.com/demo/12476.html 一.主要思路 通过itextpdf 生成想要的pdf 文件 通过itextpdf 中 XMLWorker ...
- 怎样推断 ios设备的类型(iphone,ipod,ipad)
-(bool)checkDevice:(NSString*)name { NSString* deviceType = [UIDevice currentDevice].model; NSLog(@& ...
- 使用Excel2007去反复功能时要注意的一个问题
作者:iamlaosong Excel2007有个去反复功能(菜单:数据----删除反复项).非常实用,过去须要用VBA编程实现的功能,如今点击一下图标即可了.去反复通常是指定某列或者某几列.依据这指 ...
- redis错误error记录
早上登服务器,看到程序的redis的报错, 具体如下: (error) MISCONF Redis is configured to save RDB snapshots, but is curren ...
- IntelliJ IDEA生成 Serializable 序列化 UID 的快捷键
首先创建一个类如Movie,让该类实现Serializable序列化接口. 然后我们需要依次按照以下的方法找到 Settings 之后我们需要以下几个操作,并找到 Serializable class ...
- JavaScrip函数与声明表达式
首先我们看下函数的两种命名方式 1.函数声明,声明一个函数 function test1(){ var a=0; console.log(a); //左一些操作... } 执行结果如下 我们看一下,无 ...
- git 工具 - 子模块(submodule)
From: https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%AD%90%E6%A8%A1%E5%9D%97 子模块 有种情况我们经常 ...