結果

問題 No.133 カードゲーム
ユーザー 今野博晴今野博晴
提出日時 2020-08-01 09:18:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,519 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 65,028 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-21 22:06:58
合計ジャッジ時間 2,778 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

#include <cstring>

using std::cin;
using std::cout;
using std::endl;

using std::memcpy;

static int N, A[4], B[4];
static int CN, CA[4*3*2*1+1][4], CB[4*3*2*1+1][4];

static void
make_combination_0(int val[4], int comb[][4], bool used[4], int n)
{
  for (int i = 0; i < N; i++)
  {
    if (!used[i])
    {
      used[i] = true;
      comb[CN][n] = val[i];
      if (n + 1 < N)
      {
        make_combination_0(val, comb, used, n + 1);
      }
      else
      {
        memcpy(comb[CN + 1], comb[CN], 4);
        CN++;
      }
      used[i] = false;
    }
  }
}

static void
make_combination(int val[4], int comb[][4])
{
  bool used[4] = {false};
  CN = 0;
  make_combination_0(val, comb, used, 0);
}

static bool
final_win(int a[], int b[])
{
  int win = 0;
  for (int n = 0; n < N; n++)
  {
    if (b[n] < a[n])
    {
      win++;
    }
  }
  return N < win * 2;
}

// 最終的な勝率。これが single_win_rate と一致するのかどうかを知りたい。
static double
final_win_rate()
{
  make_combination(A, CA);
  make_combination(B, CB);
  int win = 0;
  for (int ia = 0; ia < CN; ia++)
  {
    for (int ib = 0; ib < CN; ib++)
    {
      if (final_win(CA[ia], CB[ib]))
      {
        win++;
      }
    }
  }
  return double(win) / (CN * CN);
}

static double
solve()
{
  return final_win_rate();
}

int
main()
{
  cin >> N;
  for (int n = 0; n < N; n++)
  {
    cin >> A[n];
  }
  for (int n = 0; n < N; n++)
  {
    cin >> B[n];
  }
  cout << solve() << endl;
  return 0;
}
0