結果
| 問題 |
No.133 カードゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-03-17 10:42:41 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,073 bytes |
| コンパイル時間 | 2,458 ms |
| コンパイル使用メモリ | 128,568 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-01 06:20:04 |
| 合計ジャッジ時間 | 3,035 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
#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;
}