結果

問題 No.133 カードゲーム
ユーザー izumix03izumix03
提出日時 2022-03-17 10:42:41
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,073 bytes
コンパイル時間 1,203 ms
コンパイル使用メモリ 121,260 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 12:55:01
合計ジャッジ時間 2,522 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

/**
 * https://yukicoder.me/problems/no/133
 * AとBはカードゲームが好き
 * 数は 1以上 2^N未満
 * N枚ずつ配られる
 * 数字が大きい方が勝ち、二度と使えない、勝数が同じなら引き分け
 * Aが勝つ確率を返せ
 * 1 <= N <= 4
 */

int N;
vector<int> a;
vector<int> b;

void input() {
  cin >> N;

  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      int x;
      cin >> x;
      if (i == 0) {
        a.push_back(x);
      } else {
        b.push_back(x);
      }
    }
  }
}

void solve() {
  sort(a.begin(), a.end());
  int total = 0, a_win = 0;
  do {
    int a_up = 0;
    for (int i = 0; i < N; i++) {
      if (a.at(i) > b.at(i)) {
        a_up++;
      }
      if (a.at(i) < b.at(i)) {
        a_up--;
      }
    }
    if (a_up > 0) {
      a_win++;
    }
    total++;
  } while(next_permutation(a.begin(), a.end()));
  cout << a_win * 1.0 / total  * 1.0<< endl;
}

int main() {
  input();
  solve();
  return 0;
}
0