結果

問題 No.425 ジャンケンの必勝法
ユーザー chakkuchakku
提出日時 2016-09-23 00:39:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,844 bytes
コンパイル時間 1,323 ms
コンパイル使用メモリ 161,804 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 20:17:33
合計ジャッジ時間 3,723 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

int func(int i,int j){
    // negi : i
    // kamo : j
    if(i==j){
        return 0;
    }
    else if((i+1)%3==j){
        return -1;
    }
    else{
        return 1;
    }
}

int main(){
    int p0,q;cin>>p0>>q;
    double p = p0/100.0;

    random_device rnd;
    mt19937 mt(rand());
    uniform_int_distribution<> rand100(0,99);
    uniform_int_distribution<> rand3(0,2);
    uniform_int_distribution<> rand2(0,1);

    double ans = 0;
    for(int i=0;i<1000000;i++){
        int P = p0;
        bool f=false;
        int win = -1;
        ll cnt=0;
        for(int j=0;j<=10000;j++){
            cnt++;

            if(j==0){
                int negi = rand3(mt);
                int kamo = rand3(mt);
                int res = func(negi,kamo);
                if(res==1){
                    win = 1;
                    break;
                }else if(res== 0){
                    continue;
                }else{
                    win = 0;
                    break;
                }
            }
            if(j==1000){
                win = rand2(mt);
                break;
            }

            int num = rand100(mt);
            if(num < P){    // 必勝法使用
                P = max(0,P-q);
                f=true;
                int res=rand2(mt);
                if(res==0){
                    continue;
                }else{
                    win = 1;
                    break;
                }
            }else{
//                cout << "unused win method" << endl;
                P = min(100,P+q);
                f=false;
                int negi = rand3(mt);
                int kamo = rand3(mt);
                int res = func(negi,kamo);
                if(res==0){
                    continue;
                }else{
                    if(res==1){
                        win = 1;
                        break;
                    }else{
                        win = 0;
                        break;
                    }
                }
            }
        }

        if(win==1){
            ans += 1.0;
        }
    }
    ans = ans/1000000.0;
    printf("%.20f\n",ans);
}
0