結果

問題 No.425 ジャンケンの必勝法
ユーザー tashikanitashikani
提出日時 2016-09-23 00:06:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,946 bytes
コンパイル時間 1,213 ms
コンパイル使用メモリ 86,340 KB
実行使用メモリ 5,240 KB
最終ジャッジ日時 2023-08-11 05:57:59
合計ジャッジ時間 2,093 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,972 KB
testcase_01 AC 4 ms
4,964 KB
testcase_02 AC 4 ms
5,184 KB
testcase_03 AC 4 ms
4,972 KB
testcase_04 AC 5 ms
5,240 KB
testcase_05 AC 4 ms
5,044 KB
testcase_06 AC 3 ms
4,976 KB
testcase_07 AC 4 ms
5,040 KB
testcase_08 AC 4 ms
5,104 KB
testcase_09 AC 4 ms
5,228 KB
testcase_10 AC 4 ms
4,984 KB
testcase_11 AC 5 ms
5,164 KB
testcase_12 AC 6 ms
5,052 KB
testcase_13 AC 5 ms
5,164 KB
testcase_14 AC 5 ms
5,212 KB
testcase_15 AC 3 ms
5,012 KB
testcase_16 AC 3 ms
4,972 KB
testcase_17 AC 5 ms
5,044 KB
testcase_18 AC 4 ms
5,008 KB
testcase_19 AC 4 ms
4,968 KB
testcase_20 AC 5 ms
5,096 KB
testcase_21 AC 3 ms
5,052 KB
testcase_22 AC 3 ms
5,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0