結果
問題 | No.425 ジャンケンの必勝法 |
ユーザー |
|
提出日時 | 2016-09-23 00:06:56 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 1,946 bytes |
コンパイル時間 | 757 ms |
コンパイル使用メモリ | 87,208 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-17 19:44:08 |
合計ジャッジ時間 | 1,476 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 18 |
ソースコード
#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <queue>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <cctype>#include <string>#include <cstring>#include <ctime>using namespace std;inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}typedef vector<int> VI;typedef vector<VI> VVI;typedef vector<string> VS;typedef pair<int, int> PII;typedef long long LL;#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define REP(i,n) FOR(i,0,n)#define MP make_pair#define MT make_tuple#define EACH(i,c) for(auto i: c)#define SORT(c) sort((c).begin(),(c).end())#define ALL(a) (a).begin(),(a).end()#define RALL(a) (a).rbegin(), (a).rend()int main() {int p0, q;cin >> p0 >> q;const int NORMAL = 0, DEATHBLOW = 1;const int COUNT = 1000;double dp[COUNT][2][101];REP(i, COUNT) REP(j, 2) REP(k, 101) dp[i][j][k] = 0;dp[0][0][0] = 1 / 3.0;double ret = 1 / 3.0;dp[1][NORMAL][p0] = dp[0][0][0] * (100 - p0) / 100.0 / 3;dp[1][DEATHBLOW][p0] = dp[0][0][0] * p0 / 100.0 / 2;ret += dp[1][0][p0] + dp[1][1][p0];FOR(i, 2, COUNT){REP(k, 101){int p1 = min(100, k + q), p2 = max(0, k - q);double nn = dp[i - 1][NORMAL][k] * (100 - p1) / 100.0 / 3;double nd = dp[i - 1][NORMAL][k] * p1 / 100.0 / 2;double dn = dp[i - 1][DEATHBLOW][k] * (100 - p2) / 100.0 / 3;double dd = dp[i - 1][DEATHBLOW][k] * p2 / 100.0 / 2;dp[i][NORMAL][p1] += nn;dp[i][DEATHBLOW][p1] += nd;dp[i][NORMAL][p2] += dn;dp[i][DEATHBLOW][p2] += dd;ret += nd + dn + nn + dd;//cout << p1 << " " << p2 << " " << ret << endl;}}printf("%.8f", ret);return 0;}