結果
問題 | No.425 ジャンケンの必勝法 |
ユーザー |
|
提出日時 | 2016-09-23 00:06:51 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 880 bytes |
コンパイル時間 | 122 ms |
コンパイル使用メモリ | 23,808 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 19:43:39 |
合計ジャッジ時間 | 846 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:35:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | scanf("%lf %lf", &p, &q); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include "stdio.h" double p,q; double ans; void sum(int fig,double now, int pre,double con) { if (fig > 20)return; if (pre== 1) { if (now - q > 0.0) { sum(fig + 1, now - q, 1, con/2.0*(now-q)); sum(fig + 1, now-q, 0, con / 3.0*(1.0 - now + q)); ans += con*((now - q) / 2.0 + (1.0 - now + q) / 3.0); } else { sum(fig + 1, 0.0, 0, con / 3.0); ans += con / 3.0; } } else { if (now + q < 1.0) { sum(fig + 1, now + q, 1, con / 2.0 * (now + q)); sum(fig + 1, now + q, 0, con / 3.0 * (1.0 - now - q)); ans += con*((now + q) / 2.0 + (1 - now - q) / 3.0); } else { sum(fig + 1, 1.0, 1, con / 2.0); ans += con / 2.0; } } } int main() { scanf("%lf %lf", &p, &q); p = p / 100; q = q / 100; ans += 1.0 / 3.0; ans += p / 6.0; ans += (1 - p) / 9.0; sum(1, p, 1, p / 6.0); sum(1, p, 0, (1-p)/9.0); printf("%f\n", ans); return 0; }