結果

問題 No.173 カードゲーム(Medium)
ユーザー maimai
提出日時 2016-07-20 00:39:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,412 bytes
コンパイル時間 2,131 ms
コンパイル使用メモリ 168,336 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 16:56:41
合計ジャッジ時間 3,021 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 131 ms
5,376 KB
testcase_06 AC 105 ms
5,376 KB
testcase_07 AC 88 ms
5,376 KB
testcase_08 AC 87 ms
5,376 KB
testcase_09 AC 178 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int test()':
main.cpp:64:21: warning: 'choicea' may be used uninitialized [-Wmaybe-uninitialized]
   64 |     score+=(choicea + choiceb)*(choicea>choiceb ? 1 : -1);
      |            ~~~~~~~~~^~~~~~~~~~
main.cpp:31:9: note: 'choicea' was declared here
   31 |     int choicea,choiceb;
      |         ^~~~~~~
main.cpp:64:21: warning: 'choiceb' may be used uninitialized [-Wmaybe-uninitialized]
   64 |     score+=(choicea + choiceb)*(choicea>choiceb ? 1 : -1);
      |            ~~~~~~~~~^~~~~~~~~~
main.cpp:31:17: note: 'choiceb' was declared here
   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=(int)(dist1(rnd)*i);
            assert(choicea!=i);
        }
        if (pb>=dist1(rnd)){
            choiceb=0;
        }else{
            choiceb=(int)(dist1(rnd)*i);
            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=100000;

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