質問編集履歴
2
リンクの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
atcoderというプログラミングコンテストをオンラインで開催しているサイトに載っていたこの質問のタイトルにある問題について、自分のソースコードの間違いを指摘して頂けるとありがたいです。標準入力で整数値n(1<=n<=100),D(1<=D<=1e18)が与えられ、絶対誤差1e-6以下で正しい値を出力できれば正解となります。
|
6
|
+
|
7
|
+
↓こちらのリンクから問題の詳細が確認できます。
|
8
|
+
|
9
|
+
https://beta.atcoder.jp/contests/tdpc/tasks/tdpc_dice
|
6
10
|
|
7
11
|
|
8
12
|
|
1
リンクが機能していなかった。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
サイコロをn回投げて出た目の総積がDの倍数となる確率は? C++
|
test
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
atcoderというプログラミングコンテストをオンラインで開催しているサイトに載っていたこの問題
|
5
|
+
atcoderというプログラミングコンテストをオンラインで開催しているサイトに載っていたこの質問のタイトルにある問題について、自分のソースコードの間違いを指摘して頂けるとありがたいです。標準入力で整数値n(1<=n<=100),D(1<=D<=1e18)が与えられ、絶対誤差1e-6以下で正しい値を出力できれば正解となります。
|
6
|
-
|
7
|
-
|
8
6
|
|
9
7
|
|
10
8
|
|
@@ -26,7 +24,141 @@
|
|
26
24
|
|
27
25
|
```c++
|
28
26
|
|
27
|
+
#include <bits/stdc++.h>
|
28
|
+
|
29
|
+
using namespace std;
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
#define db double
|
34
|
+
|
35
|
+
#define rep0(i,n) for(int i=0;i<n;i++)
|
36
|
+
|
37
|
+
#define rep1(i,n) for(int i=1;i<=n;i++)
|
38
|
+
|
39
|
+
#define repU(i,bottom,ceiling) for(int (i)=(bottom);(i)<=(ceiling);(i)++)
|
40
|
+
|
41
|
+
#define repD(i,ceiling,bottom) for(int (i)=(ceiling);(i)>=(bottom);(i)--)
|
42
|
+
|
43
|
+
#define V vector
|
44
|
+
|
45
|
+
#define vi vector<int>
|
46
|
+
|
47
|
+
#define pub(v,el) v.push_back(el)
|
48
|
+
|
49
|
+
#define pob(v) v.pop_back
|
50
|
+
|
51
|
+
#define ci(a) cin>>a
|
52
|
+
|
53
|
+
#define lco(a) cout<<a<<endl
|
54
|
+
|
55
|
+
#define co(a) cout<<a
|
56
|
+
|
57
|
+
#define vco(v) rep0(i,v.size()){ co(v[i]<<' '); } co('\n')
|
58
|
+
|
59
|
+
#define pii pair<int,int>
|
60
|
+
|
61
|
+
#define mp(a,b) make_pair(a,b)
|
62
|
+
|
63
|
+
#define fir first
|
64
|
+
|
65
|
+
#define sec second
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
typedef long long ll;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
const int dir[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
|
74
|
+
|
75
|
+
const int Inf=2e9+1e8;
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
template <typename T,typename U>
|
80
|
+
|
81
|
+
pair<T,U> operator+(const pair<T,U> & l,const pair<T,U> & r) {
|
82
|
+
|
83
|
+
return {l.fir+r.fir,l.sec+r.sec};
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
template <typename T,typename U>
|
90
|
+
|
91
|
+
pair<T,U> operator-(const pair<T,U> & l,const pair<T,U> & r) {
|
92
|
+
|
93
|
+
return {l.fir-r.fir,l.sec-r.sec};
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
int order(ll n,int p){
|
100
|
+
|
101
|
+
if((ll)n%p) return 0;
|
102
|
+
|
103
|
+
return 1+order(n/(ll)p,p);
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
int main(){
|
110
|
+
|
111
|
+
int n,p[3];
|
112
|
+
|
113
|
+
ll d;
|
114
|
+
|
115
|
+
ci(n>>d);
|
116
|
+
|
117
|
+
p[0]=order(d,2);
|
118
|
+
|
119
|
+
p[1]=order(d,3);
|
120
|
+
|
121
|
+
p[2]=order(d,5);
|
122
|
+
|
123
|
+
if(d/(1<<p[0])/pow(3,p[1])/pow(5,p[2])>1){
|
124
|
+
|
125
|
+
lco('0');
|
126
|
+
|
127
|
+
return 0;
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
V<V<V<V<db>>>> dp=V<V<V<V<db>>>>(n+1, V<V<V<db>>>(p[0]+1,V<V<db>>(p[1]+1,V<db>(1+p[2],0))));
|
132
|
+
|
133
|
+
dp[0][0][0][0]=1;
|
134
|
+
|
29
|
-
|
135
|
+
repU(cnt,0,n){
|
136
|
+
|
137
|
+
repU(a,0,p[0]){
|
138
|
+
|
139
|
+
repU(b,0,p[1]){
|
140
|
+
|
141
|
+
repU(c,0,p[2]){
|
142
|
+
|
143
|
+
if(!cnt){ if(a||b||c){ dp[cnt][a][b][c]=0; } continue; }
|
144
|
+
|
145
|
+
dp[cnt][a][b][c]= (dp[cnt-1][a][b][c]+dp[cnt-1][max(0,a-1)][b][c]+dp[cnt-1][a][max(0,b-1)][c]+dp[cnt-1][a][b][max(0,c-1)]+dp[cnt-1][max(0,a-2)][b][c]+dp[cnt-1][max(a-1,0)][max(0,b-1)][c])/6;
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
printf("%.10f\n",dp[n][p[0]][p[1]][p[2]]);
|
156
|
+
|
157
|
+
return 0;
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
30
162
|
|
31
163
|
```
|
32
164
|
|