标签:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
int a, b;
int v[205];
bool check(int x, int y, int num) {
if (num == a || num == b) memset(v, -1, sizeof(v));
if (!num) return 1;
if (num < 0) return 0;
int &t = v[num];
if (~t) return t;
t = check(x, y, num - x) | check(x, y, num - y);
return t;
}
class KingXNewCurrency {
public:
int howMany(int A, int B, int X) {
int ans = 0;
a = A, b = B;
if (a % X == 0 && b % X == 0) ans = -1;
else {
for (int i = 1; i <= 200; ++i) {
if (check(X, i, a) && check(X, i, b)) ++ans;
}
}
return ans;
}
};
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
const int N = 55;
double dp[N][N][2];
class KingXMagicSpells {
public:
double expectedNumber(vector <int> ducks, vector <int> spellOne, vector <int> spellTwo, int K) {
int n = ducks.size();
double ans = 0.0;
for (int mask = 0; mask <= 30; ++mask) {
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; ++i) dp[0][i][ducks[i - 1] >> mask & 1] = 1.0;
for (int i = 1; i <= K; ++i)
for (int j = 1; j <= n; ++j)
for (int k = 0; k < 2; ++k) {
dp[i][j][k ^ (spellOne[j - 1] >> mask & 1)] += dp[i - 1][j][k] * 0.5;
dp[i][spellTwo[j - 1] + 1][k] += dp[i - 1][j][k] * 0.5;
}
ans += dp[K][1][1] * (1 << mask);
}
return ans;
}
};
标签:
原文地址:http://blog.csdn.net/mlzmlz95/article/details/46508017