結果

問題 No.173 カードゲーム(Medium)
ユーザー maimai
提出日時 2016-07-20 00:57:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 438 ms / 3,000 ms
コード長 2,433 bytes
コンパイル時間 1,545 ms
コンパイル使用メモリ 169,184 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-05 20:25:29
合計ジャッジ時間 4,899 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 31 ms
4,384 KB
testcase_02 AC 372 ms
4,380 KB
testcase_03 AC 388 ms
4,380 KB
testcase_04 AC 370 ms
4,380 KB
testcase_05 AC 335 ms
4,376 KB
testcase_06 AC 273 ms
4,380 KB
testcase_07 AC 241 ms
4,380 KB
testcase_08 AC 234 ms
4,380 KB
testcase_09 AC 438 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int test()’ 内:
main.cpp:65:21: 警告: ‘choicea’ may be used uninitialized [-Wmaybe-uninitialized]
   65 |     score+=(choicea + choiceb)*(choicea>choiceb ? 1 : -1);
      |            ~~~~~~~~~^~~~~~~~~~
main.cpp:31:9: 備考: ‘choicea’ はここで定義されています
   31 |     int choicea,choiceb;
      |         ^~~~~~~
main.cpp:65:21: 警告: ‘choiceb’ may be used uninitialized [-Wmaybe-uninitialized]
   65 |     score+=(choicea + choiceb)*(choicea>choiceb ? 1 : -1);
      |            ~~~~~~~~~^~~~~~~~~~
main.cpp:31:17: 備考: ‘choiceb’ はここで定義されています
   31 |     int choicea,choiceb;
      |                 ^~~~~~~

ソースコード

diff #

#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;
}
0