結果

問題 No.173 カードゲーム(Medium)
ユーザー tnakao0123tnakao0123
提出日時 2016-03-25 08:43:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 889 ms / 3,000 ms
コード長 1,646 bytes
コンパイル時間 1,205 ms
コンパイル使用メモリ 91,348 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-09 23:48:52
合計ジャッジ時間 7,336 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
6,816 KB
testcase_01 AC 108 ms
6,940 KB
testcase_02 AC 765 ms
6,944 KB
testcase_03 AC 767 ms
6,940 KB
testcase_04 AC 747 ms
6,944 KB
testcase_05 AC 678 ms
6,940 KB
testcase_06 AC 590 ms
6,944 KB
testcase_07 AC 558 ms
6,944 KB
testcase_08 AC 558 ms
6,940 KB
testcase_09 AC 889 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 173.cc: No.173 カードゲーム(Medium) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 20;
const int TN = 500000;

/* typedef */

typedef vector<int> vi;

/* global variables */

/* subroutines */

/* main */

int main() {
  srand(time(NULL));

  int n;
  double pa, pb;
  cin >> n >> pa >> pb;
  //printf("pa=%.5lf, pb=%.5lf\n", pa, pb);

  vi as(n), bs(n);

  for (int i = 0; i < n; i++) cin >> as[i];
  for (int i = 0; i < n; i++) cin >> bs[i];
  sort(as.begin(), as.end());
  sort(bs.begin(), bs.end());

  int awin = 0;
  for (int t = 0; t < TN; t++) {
    vi as0(as), bs0(bs);
    int aw = 0, bw = 0;

    for (int i = 0; i < n; i++) {
      double ra = (double)rand() / RAND_MAX;
      double rb = (double)rand() / RAND_MAX;
      //printf("ra=%.5lf, rb=%.5lf\n", ra, rb);

      int ia = 0, ib = 0;
      if (i < n - 1) {
	if (ra >= pa) ia = rand() % (n - 1 - i) + 1;
	if (rb >= pb) ib = rand() % (n - 1 - i) + 1;
      }
      
      int ai = as0[ia], bi = bs0[ib];
      if (ai > bi) aw += ai + bi;
      else if (ai < bi) bw += ai + bi;
      //printf("i=%d: as[%d]=%d, bs[%d]=%d\n", i, ia, ai, ib, bi);

      as0.erase(as0.begin() + ia);
      bs0.erase(bs0.begin() + ib);
    }

    if (aw > bw) awin++;
  }

  printf("%.5lf\n", (double)awin / TN);
  return 0;
}
0