Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <map>
- #include <set>
- #include <ctime>
- #include <cassert>
- #include <queue>
- using namespace std;
- #define f first
- #define s second
- #define mp make_pair
- #define pb push_back
- #define forit(it,con) for (typeof(con.begin()) it = con.begin(); it != con.end(); ++it)
- #define f0(a) memset(a, 0, sizeof(a))
- #define all(v) v.begin(), v.end()
- #define pii pair<int,int>
- #define vi vector<int>
- #define ll long long
- #ifdef WIN32
- #define I64 "%I64d"
- #else
- #define I64 "%lld"
- #endif
- int X, Y, Z, n;
- struct Mat {
- double a[2][2];
- Mat() {
- memset(a, 0, sizeof(a));
- }
- Mat operator * (Mat other) {
- Mat c;
- for (int i = 0; i < 2; ++i)
- for (int j = 0; j < 2; ++j)
- for (int k = 0; k < 2; ++k)
- c.a[i][j] += a[i][k] * other.a[k][j];
- return c;
- }
- }a;
- inline double getProb(double i, double n) {
- return ((i + 1) * (n - i) * 2 - 1) / (n * n);
- }
- inline double Pow(int n, double P) {
- Mat a, res;
- res.a[0][0] = res.a[1][1] = 1;
- a.a[0][0] = 1 - P;
- a.a[0][1] = P;
- a.a[1][0] = P;
- a.a[1][1] = 1 - P;
- while (n > 0) {
- if (n & 1) res = res * a;
- a = a * a;
- n >>= 1;
- }
- return res.a[1][0];
- }
- void Solve() {
- double ans = 0;
- for (int x = 0; x < X; ++x)
- for (int y = 0; y < Y; ++y)
- for (int z = 0; z < Z; ++z) {
- ans += Pow(n, getProb(x, X) * getProb(y, Y) * getProb(z, Z));
- }
- printf("%.6lf\n", ans);
- }
- int main() {
- #ifdef LOCAL
- freopen("in","r",stdin);
- freopen("out","w",stdout);
- #endif
- int tests;
- scanf("%d", &tests);
- for (int test = 1; test <= tests; ++test) {
- scanf("%d%d%d%d", &X, &Y, &Z, &n);
- printf("Case %d: ", test);
- Solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement