結果
| 問題 |
No.174 カードゲーム(Hard)
|
| コンテスト | |
| ユーザー |
__math
|
| 提出日時 | 2015-03-27 00:55:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 158 ms / 2,000 ms |
| コード長 | 2,467 bytes |
| コンパイル時間 | 996 ms |
| コンパイル使用メモリ | 102,064 KB |
| 実行使用メモリ | 12,012 KB |
| 最終ジャッジ日時 | 2024-07-06 21:10:20 |
| 合計ジャッジ時間 | 2,719 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <limits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)
// #pragma comment(linker,"/STACK:36777216")
template<class T> void chmax(T& l, const T r) { l = max(l, r); }
template<class T> void chmin(T& l, const T r) { l = min(l, r); }
double memo[1<<20];
double choice[20][21];
int n;
int popcount(ll x) {
x = (x & 0x5555555555555555ULL) + ((x & 0xAAAAAAAAAAAAAAAAULL) >> 1);
x = (x & 0x3333333333333333ULL) + ((x & 0xCCCCCCCCCCCCCCCCULL) >> 2);
x = (x & 0x0F0F0F0F0F0F0F0FULL) + ((x & 0xF0F0F0F0F0F0F0F0ULL) >> 4);
return (int)(x * 0x0101010101010101ULL >> 56);
}
void f(double p) {
memset(memo, 0, sizeof(memo));
memset(choice, 0, sizeof(choice));
memo[(1 << n) - 1] = 1.0;
for (int F = (1 << n) - 1; F > 0; F--) {
int pop = popcount(F);
int bit = 0;
while ((F & (1 << bit)) == 0) bit++;
double q = memo[F];
if (pop == 1) {
memo[F ^ (1 << bit)] += q;
choice[bit][n - pop] += q;
} else {
memo[F ^ (1 << bit)] += p * q;
choice[bit][n - pop] += p * q;
bit++;
double r = (1 - p) / (pop - 1);
for (; bit < n; bit++) {
if (F & (1 << bit)) {
memo[F ^ (1 << bit)] += r * q;
choice[bit][n - pop] += r * q;
}
}
}
}
}
double a_choice[20][21], b_choice[20][21];
int main() {
double pa, pb;
cin >> n >> pa >> pb;
vector<int> a(n), b(n);
FOR(i, n) cin >> a[i];
FOR(i, n) cin >> b[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
f(pa);
memcpy(a_choice, choice, sizeof(choice));
f(pb);
memcpy(b_choice, choice, sizeof(choice));
double ans = 0;
FOR(i, n) FOR(j, n) FOR(k, n) {
double p = a_choice[i][k] * b_choice[j][k];
double sm = a[i] + b[j];
if (a[i] > b[j]) {
ans += p * sm;
}
}
printf("%.15lf\n",ans);
}
__math