結果

問題 No.159 刺さらないUSB
ユーザー koyumeishikoyumeishi
提出日時 2015-03-05 00:01:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 2,292 bytes
コンパイル時間 889 ms
コンパイル使用メモリ 83,800 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 16:35:06
合計ジャッジ時間 1,997 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

//マルコフなんちゃらの練習

//[n*p] * [p*m] => [n*m]
template<class T>
vector< vector<T> > multmat(const vector<vector<T> > &A, const vector<vector<T>> &B, int n, int p, int m){
	vector<vector<T> > C(n, vector<T>(m,0));
	for(int i=0; i<n; i++){
		for(int k=0; k<p; k++){
			for(int j=0; j<m; j++){
				C[i][j] += A[i][k] * B[k][j];
				//C[i][j] %= mod;
			}
		}
	}
	return C;
}

//A[n*n]^k 
template<class T>
vector< vector<T> > mat_pow(vector<vector<T> > A, int k){
	int n = A.size();
	vector<vector<T> > ret(n, vector<T>(n, 0) );
	for(int i=0; i<n; i++){
		ret[i][i] = 1;
	}
	while(k>0){
		if(k&1) ret = multmat(A,ret, n,n,n);
		A = multmat(A,A, n,n,n);
		k>>=1;
	}
	return ret;
}

void print_vec(const vector<vector<double>> &v){
#ifdef DBG_
	for(auto l : v){
		for(auto x : l){
			cerr << x << "\t";
		}
		cerr << endl;
	}
	cerr << endl;
#endif
}

int main(){
	double p,q;
	cin >> p >> q;

	//遷移図的な何か
	// aは表の状態、 bは裏の状態、 sははじめ、 tは終わり
	// s -> a (p)
	//   -> b (1-p)
	// a -> t (q)
	//   -> b (1-q)
	// b -> a (1)
	// t -> t (1)

	//遷移行列
	vector<vector<double>> P(4, vector<double>(4,0));
	P = {
	//   s   a    b   t
		{0,  p, 1-p,  0},
		{0,  0, 1-q,  q},
		{0,  1,   0,  0},
		{0,  0,   0,  1}	// <- ここが吸収状態
	};
	print_vec(P);

	//初期状態
	vector<vector<double>> S(1, vector<double>(4,0));
	S = { {1,0,0,0} };
	print_vec(S);

	double p1, p2;

	auto P2 = mat_pow<double>(P, 2);	//0回ひっくり返す
	print_vec(P2);

	auto P3 = mat_pow<double>(P, 3);	//1回ひっくり返す
	print_vec(P3);

	auto P4 = mat_pow<double>(P, 4);	//2回ひっくり返す
	print_vec(P4);

	{
		auto tmp = multmat<double>(S, P3, 1,4,4);
		auto tmp_ = multmat<double>(S, P2, 1,4,4);

		print_vec(tmp);
		print_vec(tmp_);

		p1 = tmp[0][3] - tmp_[0][3];
	}
	{
		auto tmp = multmat<double>(S, P4, 1,4,4);
		auto tmp_ = multmat<double>(S, P3, 1,4,4);

		print_vec(tmp);
		print_vec(tmp_);

		p2 = tmp[0][3] - tmp_[0][3];
	}

	//cerr << p1 << " " << p2 << endl;
	cout << (p1<p2 ? "YES" : "NO") << endl;
	return 0;
}
0