結果
| 問題 |
No.173 カードゲーム(Medium)
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2015-07-27 23:28:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2,356 ms / 3,000 ms |
| コード長 | 1,499 bytes |
| コンパイル時間 | 833 ms |
| コンパイル使用メモリ | 73,128 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-16 04:20:56 |
| 合計ジャッジ時間 | 14,010 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
48 | scanf("%d %lf %lf", &N, &_PA, &_PB);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:53:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
53 | scanf("%d", A+i);
| ~~~~~^~~~~~~~~~~
main.cpp:57:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
57 | scanf("%d", B+i);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <cstdio>
#include <vector>
#include <random>
#include <algorithm>
const int T = 1600000;
int N;
double _PA, _PB;
int PA, PB;
int A[20], B[20];
std::vector<int> va, vb;
std::random_device randomDevice;
std::mt19937 engine(randomDevice());
int simulate(int point_a, int point_b){
if(va.empty()){
return point_a > point_b;
}
int index, index2;
if(va.size() == 1 || engine() % 1000 < PA){
index = 0;
}else{
index = 1 + (engine() % (va.size() - 1)); // 適当に剰余をとるとダメらしい
}
if(vb.size() == 1 || engine() % 1000 < PB){
index2 = 0;
}else{
index2 = 1 + (engine() % (vb.size() - 1));
}
int point = va[index] + vb[index2];
if(va[index] > vb[index2]){
point_a += point;
}else if(va[index] < vb[index2]){
point_b += point;
}
va.erase(va.begin() + index);
vb.erase(vb.begin() + index2);
return simulate(point_a, point_b);
}
int main(){
scanf("%d %lf %lf", &N, &_PA, &_PB);
PA = _PA * 1000;
PB = _PB * 1000;
for(int i=0;i<N;i++){
scanf("%d", A+i);
}
for(int i=0;i<N;i++){
scanf("%d", B+i);
}
std::sort(A, A+N);
std::sort(B, B+N);
double res = 0.0;
for(int i=0;i<T;i++){
va.resize(N);
vb.resize(N);
std::copy(A, A+N, va.begin());
std::copy(B, B+N, vb.begin());
res += simulate(0, 0);
}
printf("%.6f\n", 1. * res / T);
}
tottoripaper