結果

問題 No.425 ジャンケンの必勝法
ユーザー kurenai3110kurenai3110
提出日時 2016-09-23 01:09:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,167 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 77,604 KB
実行使用メモリ 19,432 KB
最終ジャッジ日時 2023-08-11 06:01:31
合計ジャッジ時間 2,620 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
4,384 KB
testcase_01 AC 15 ms
4,384 KB
testcase_02 AC 16 ms
4,380 KB
testcase_03 AC 18 ms
10,540 KB
testcase_04 AC 27 ms
17,576 KB
testcase_05 AC 18 ms
10,700 KB
testcase_06 AC 25 ms
16,240 KB
testcase_07 AC 27 ms
18,548 KB
testcase_08 AC 17 ms
9,616 KB
testcase_09 AC 18 ms
10,704 KB
testcase_10 AC 16 ms
4,380 KB
testcase_11 AC 28 ms
18,652 KB
testcase_12 AC 26 ms
18,596 KB
testcase_13 AC 26 ms
19,280 KB
testcase_14 AC 27 ms
18,772 KB
testcase_15 AC 26 ms
19,260 KB
testcase_16 AC 26 ms
19,376 KB
testcase_17 AC 26 ms
18,632 KB
testcase_18 AC 17 ms
10,644 KB
testcase_19 AC 18 ms
10,772 KB
testcase_20 AC 27 ms
18,748 KB
testcase_21 AC 26 ms
19,208 KB
testcase_22 AC 28 ms
19,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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