結果

問題 No.301 サイコロで確率問題 (1)
ユーザー syoken_desukasyoken_desuka
提出日時 2015-11-14 00:08:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,551 bytes
コンパイル時間 2,635 ms
コンパイル使用メモリ 155,140 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 17:25:53
合計ジャッジ時間 3,026 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 184 ms
4,352 KB
testcase_01 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:29:15: warning: ISO C++11 requires whitespace after the macro name
 #define DEBUG1{}
               ^
main.cpp:29: warning: "DEBUG1" redefined
 #define DEBUG1{}
 
main.cpp:24: note: this is the location of the previous definition
 #define DEBUG1(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
 
main.cpp:30:15: warning: ISO C++11 requires whitespace after the macro name
 #define DEBUG2{}
               ^
main.cpp:30: warning: "DEBUG2" redefined
 #define DEBUG2{}
 
main.cpp:25: note: this is the location of the previous definition
 #define DEBUG2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; DEBUG1(var1); }
 
main.cpp:31:15: warning: ISO C++11 requires whitespace after the macro name
 #define DEBUG3{}
               ^
main.cpp:31: warning: "DEBUG3" redefined
 #define DEBUG3{}
 
main.cpp:26: note: this is the location of the previous definition
 #define DEBUG3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; DEBUG2(var1, var2); }
 
main.cpp:32:15: warning: ISO C++11 requires whitespace after the macro name
 #define DEBUG4{}
               ^
main.cpp:32: warning: "DEBUG4" redefined
 #define DEBUG4{}
 
main.cpp:27: note: this is the location of the previous definition
 #define DEBUG4(var0, var1, var2, var3) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; DEBUG3(var1, var2, var3); }
 

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
//諸機能
#pragma region MACRO
#define ANSWER(x) cerr << "answer: "; cout << (x) << endl
#define DOUBLE_ANSWER(x) cerr << "answer: "; cout << setprecision(10) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define ALL(a) begin((a)),end((a))
#define FILL(a,n) for(auto &hoge : (a)) hoge = (n)
#define mp make_pair
#define EXIST(container, n) ((container).find((n)) != (container).end())
#define STOI(s,i,l) stoi(SUBSTR(s,i,l))
#define SUBSTR(s,i,l) string((s), (i), (l))
#define NPI_TO_RAD(x) (180.0*x/PI)
#define RAD_TO_NPI(x) (PI/180.0*x)
#pragma endregion


//デバッグなどの支援
#pragma region CODING_SUPPORT
#define DEBUG1(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define DEBUG2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; DEBUG2(var1, var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; DEBUG3(var1, var2, var3); }
#ifndef _DEBUG //デバッグでないなら、計算時間短縮のためにエラー出力を無効化
#define DEBUG1{}
#define DEBUG2{}
#define DEBUG3{}
#define DEBUG4{}
#endif

//typedef(書き換える、書き足す可能性ある)
#pragma region TYPE_DEF
typedef long long ll; 
typedef pair<int,int> pii;
typedef pair<string,string> pss;
typedef pair<int,string>pis;
typedef pair<string,int>psi;
typedef vector<string> vs;
typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9 + 7)
#pragma endregion

struct Matrix {
	vector<vector<double> > v, w;
	Matrix() {}
	Matrix(int n, int m) : v(n, vector<double>(m)) { }
	inline int height() const { return (int)v.size(); }
	inline int width() const { return (int)v[0].size(); }
	inline double& at(int i, int j) { return v[i][j]; }
	inline const double& at(int i, int j) const { return v[i][j]; }
	static Matrix identity(int n) {
		Matrix A(n, n);
		rep(i, n) A.at(i, i) = 1;
		return A;
	}
	inline static Matrix identity(const Matrix& A) { return identity(A.height()); }
	Matrix& operator*=(const Matrix& B)
	{
		int n = height(), m = B.width(), p = B.height();
		assert(p == width());
		w.assign(n, vector<double>(m, 0));
		rep(i, n)
		{
			rep(j, m) {
				double x = 0;
				rep(k, p)
				{
					x += at(i, k) * B.at(k, j);
				}
				w[i][j] = x;
			}
		}
		v.swap(w);
		return *this;
	}
};
Matrix operator^(const Matrix& t, ll k) {
	Matrix A = t, B = Matrix::identity(t);
	while (k) {
		if (k & 1) B *= A;
		A *= A;
		k >>= 1;
	}
	return B;
}


int main()
{
	ll n;
	cin >> n;
	Matrix abase(6, 6);
	Matrix bbase(7, 7);
	Matrix initaa(6, 1);
	Matrix initab(7, 1);
	initab.at(6, 0) = 1;
	rep(i, 6)
	{
		initaa.at(i, 0) = 1;
		abase.at(0, i) = 1.0 / 6;
		bbase.at(0, i) = 1.0 / 6;
	}
	initaa.at(0, 0) = 0;
	rep(i, 5)
	{
		abase.at(1 + i, i) = 1;
		bbase.at(i+1,i) = 1;
	}
	bbase.at(0, 6) = 1;
	bbase.at(6,6) = 1;

	rep(count, n)
	{
		ll k;
		cin >> k;
		Matrix tmpa = abase ^ k;
		Matrix tmpb = bbase ^ k;
		double a0 = 0;
		rep(i, 6)
		{
			a0 += tmpa.at(0, i) * initaa.at(i, 0);
		}
		double b0 = 0;
		rep(i, 7)
		{
			b0 += tmpb.at(0, i) * initab.at(i, 0);
		}
		DEBUG1(a0);
		DEBUG1(b0);
		cout << setprecision(15) << b0 / ( 1 - a0 ) << endl;
	}

	return 0;
}

0