結果
問題 |
No.425 ジャンケンの必勝法
|
ユーザー |
![]() |
提出日時 | 2016-09-23 01:09:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 1,167 bytes |
コンパイル時間 | 582 ms |
コンパイル使用メモリ | 79,872 KB |
実行使用メモリ | 19,664 KB |
最終ジャッジ日時 | 2024-11-17 19:46:01 |
合計ジャッジ時間 | 1,810 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 18 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <queue> #include <cmath> #include <map> #include <iomanip> using namespace std; typedef pair<double, int> PP; int P, Q; double bfs() { queue<PP> que; que.push(make_pair(1./3,P)); double ans = 1. / 3; int cnt = 0; while (cnt!=1000000) { pair<double,int> p = que.front(); que.pop(); //if (p.second > 100)ans += p.first / 2; //else if(p.second>=0&&p.second<=100) ans += p.first / 2 * p.second/100; //if (p.second < 0)ans += p.first / 3; //else if(p.second>=0&&p.second<=100) ans += p.first / 3 * (100-p.second)/100; //cout << ans << endl; //cout << p.second << endl; if(p.second+Q<100) que.push(make_pair(p.first / 3 * (100 - p.second) / 100,p.second + Q)); //if (p.second < 100) else if(p.second!=100) que.push(make_pair(p.first / 3 * (100 - p.second) / 100, 100)); if(p.second-Q>0)que.push(make_pair(p.first / 2 * p.second / 100,p.second - Q)); //if (p.second > 0) else if(p.second!=0) que.push(make_pair(p.first / 2 * p.second / 100, 0)); cnt++; } return ans; } int main() { cin >> P >> Q; cout <<fixed<<setprecision(7)<< bfs() << endl; return 0; }