結果
| 問題 |
No.173 カードゲーム(Medium)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-20 00:57:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 466 ms / 3,000 ms |
| コード長 | 2,433 bytes |
| コンパイル時間 | 1,939 ms |
| コンパイル使用メモリ | 172,684 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-15 17:27:46 |
| 合計ジャッジ時間 | 5,054 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
コンパイルメッセージ
main.cpp: In function 'int test()':
main.cpp:65:21: warning: 'choicea' may be used uninitialized [-Wmaybe-uninitialized]
65 | score+=(choicea + choiceb)*(choicea>choiceb ? 1 : -1);
| ~~~~~~~~~^~~~~~~~~~
main.cpp:31:9: note: 'choicea' was declared here
31 | int choicea,choiceb;
| ^~~~~~~
main.cpp:65:21: warning: 'choiceb' may be used uninitialized [-Wmaybe-uninitialized]
65 | score+=(choicea + choiceb)*(choicea>choiceb ? 1 : -1);
| ~~~~~~~~~^~~~~~~~~~
main.cpp:31:17: note: 'choiceb' was declared here
31 | int choicea,choiceb;
| ^~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;
#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007
template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}
mt19937 rnd; // 64ビット版のメルセンヌ・ツイスター
uniform_real_distribution<double> dist1(0.0,1.0);
int n;
int carda[30];
int cardb[30];
double pb,pa;
int test(){
int i,j;
int bita=0,bitb=0,turn=0;
int choicea,choiceb;
int score=0;
uint gen;
double gend;
for (i=n;2<=i;i--){
if (pa>=dist1(rnd)){
choicea=0;
}else{
choicea=1+(int)(dist1(rnd)*(i-1));
assert(choicea!=i);
}
if (pb>=dist1(rnd)){
choiceb=0;
}else{
choiceb=1+(int)(dist1(rnd)*(i-1));
assert(choiceb!=i);
}
for (j=0;j<=choicea;j++)
if (bita&(1<<j)) choicea++;
bita|=(1<<choicea);
choicea=carda[choicea];
for (j=0;j<=choiceb;j++)
if (bitb&(1<<j)) choiceb++;
bitb|=(1<<choiceb);
choiceb=cardb[choiceb];
score+=(choicea + choiceb)*(choicea>choiceb ? 1 : -1);
}
// final
for (j=0;j<n;j++)
if (~bita&(1<<j)){choicea=carda[j];break;}
for (j=0;j<n;j++)
if (~bitb&(1<<j)){choiceb=cardb[j];break;}
score+=(choicea + choiceb)*(choicea>choiceb ? 1 : -1);
return score > 0;
}
const int trycount=180000;
int main(){
int i,j,k,l;
cin>>n>>pa>>pb;
for (i=0;i<n;i++)
scanf("%d",carda+i);
for (i=0;i<n;i++)
scanf("%d",cardb+i);
sort(carda,carda+n);
sort(cardb,cardb+n);
int won=0;
for (i=0;i<trycount;i++){
won+=test();
}
cout<<((double)won/trycount)<<endl;
return 0;
}