結果

問題 No.425 ジャンケンの必勝法
コンテスト
ユーザー akakimidori
提出日時 2017-04-24 15:38:52
言語 C90
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 524 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 170 ms
コンパイル使用メモリ 37,352 KB
最終ジャッジ日時 2026-02-24 00:37:34
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<stdio.h>

double calc(int depth,int p,int q){
  if(depth>=18){
    return (0.5+2.0/3.0)/2;
  }
  double h=1.0/2.0;
  double t=1.0/3.0;
  double f=1.0/100.0;
  if(p<=0){
    return t+calc(depth+1,q,q)*t;
  } else if(p>=100){
    return h+calc(depth+1,100-q,q)*h;
  }
  return (h+calc(depth+1,p-q,q)*h)*p*f
    +(t+calc(depth+1,p+q,q)*t)*(100-p)*f;
}

void run(void){
  int p,q;
  scanf("%d%d",&p,&q);

  double ans=1.0/3.0+calc(0,p,q)/3.0;
  printf("%.6lf\n",ans);
  return;
}

int main(void){
  run();
  return 0;
}
0