2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 A Weather Patterns
2017-09-27 22:30
465 查看
Consider a system which is described at any time as being in one of a set of NN distinct
states, 1,2,3,...,N1,2,3,...,N.
We denote the time instants associated with state changes as t
= 1,2,...t=1,2,...,
and the actual state at time tt as a_{ij}=p=[s_{i}=j\
|\ s_{i-1}=i], 1\le i,j \le Naij=p=[si=j ∣ si−1=i],1≤i,j≤N.
For the special case of a discrete, first order, Markovchain, the probabilistic description for the current state (at time tt)
and the predecessor state is s_{t}st.
Furthermore we only consider those processes being independent of time, thereby leading to the set of state transition probability a_{ij}aij of
the form: with the properties a_{ij}
\geq 0aij≥0 and \sum_{i=1}^{N}
A_{ij} = 1∑i=1NAij=1.
The stochastic process can be called an observable Markovmodel. Now, let us consider the problem of a simple 4-state Markov model of weather. We assume that once a day (e.g., at noon), the weather is observed as being one of the following:
State 11:
snow
State 22:
rain
State 33:
cloudy
State 44:
sunny
The matrix A of state transition probabilities is:
A
= \{a_{ij}\}= \begin{Bmatrix} a_{11}&a_{12}&a_{13}&a_{14} \\ a_{21}&a_{22}&a_{23}&a_{24} \\ a_{31}&a_{32}&a_{33}&a_{34} \\ a_{41}&a_{42}&a_{43}&a_{44} \end{Bmatrix}A={aij}=⎩⎪⎪⎨⎪⎪⎧a11a21a31a41a12a22a32a42a13a23a33a43a14a24a34a44⎭⎪⎪⎬⎪⎪⎫
Given the model, several interestingquestions about weather patterns over time can be asked (and answered). We canask the question: what is the probability
(according to the given model) thatthe weather for the next k days willbe? Another interesting question we can ask: given that the model is in a knownstate, what is the expected number of consecutive days to stay
in that state?Let us define the observation sequence OOas O
= \left \{ s_{1}, s_{2}, s_{3}, ... , s_{k} \right \}O={s1,s2,s3,...,sk},
and the probability of the observation sequence OOgiven
the model is defined as p(O|model)p(O∣model).
Also, let the expected number of consecutive days to stayin state ii be E_{i}Ei.
Assume that the initial state probabilities p[s_{1}
= i] = 1, 1 \leq i \leq Np[s1=i]=1,1≤i≤N.
Bothp(O|model)p(O∣model)and E_{i}Ei are
real numbers.
the state transition probabilities. Line 55 for
the observation sequence O_{1}O1,
and line 66 for
the observation sequence O_{2}O2.
Line 77and
line 88 for
the states of interest to find the expected number of consecutive days to stay in these states.
Line 11: a_{11}\
a_{12}\ a_{13}\ a_{14}a11 a12 a13 a14
Line 22: a_{21}\
a_{22}\ a_{23}\ a_{34}a21 a22 a23 a34
Line 33: a_{31}\
a_{32}\ a_{33}\ a_{34}a31 a32 a33 a34
Line 44: a_{41}\
a_{42}\ a_{43}\ a_{44}a41 a42 a43 a44
Line 55: s_{1}\
s_{2}\ s_{3}\ ...\ s_{k}s1 s2 s3 ... sk
Line 66: s_{1}\
s_{2}\ s_{3}\ ...\ s_{l}s1 s2 s3 ... sl
Line 77: ii
Line 88: jj
line 22 are
used to show the probabilities of the observation sequences O_{1}O1and O_{2}O2 respectively.
Line 33 and
line 44 are
for the expected number of consecutive days to stay in states ii and jj respectively.
Line 11: p[O_{1}
| model]p[O1∣model]
Line 22: p[O_{2}
| model]p[O2∣model]
Line 33: E_{i}Ei
Line 44: E_{j}Ej
Please be reminded that the floating number should accurate to 10^{-8}10−8.
2017
ACM-ICPC 亚洲区(南宁赛区)网络赛
题意:先给你4 * 4 的矩阵,表示天气 i 到天气 j 转变的概率,然后输入 k 个数字,以 ‘\n’ 表示输入结束,这 k 个数字的意思以
这组数字举例,其实就是天气从 4 转变为 4,然后从 4 转变为 3,然后从 3 转变为 2,然后从 2 转变为 2,然后从 2 转变为 1,然后从 1 转变为 1,然后从1 转变为 3,然后从3 转变为 3的概率是多少。
这样的输入数据有两组
然后输入两个数字 i 和 j ,这两个数字都表示天气的状况为 i 和 j 一直不变,不管天数增加多少,然后要你求一直不变的数学期望是多少。
附代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long LL;
///o(っ。Д。)っ AC万岁!!!!!!!!!!!!!!
const int maxn = 10;
double maps[maxn][maxn] = {};
int main()
{
for(int i = 1; i <= 4; i++)
{
for(int j = 1; j <= 4; j++)
{
scanf("%lf", &maps[i][j]);
}
}
double pp = 1.0;
int d1, d2;
char ch;
scanf("%d", &d1);
while(scanf("%d%c", &d2, &ch) != EOF)
{
pp *= maps[d1][d2];
d1 = d2;
if(ch == '\n') break;
}
printf("%.8lf\n", pp);
pp = 1.0;
scanf("%d", &d1);
while(scanf("%d%c", &d2, &ch) != EOF)
{
pp *= maps[d1][d2];
d1 = d2;
if(ch == '\n') break;
}
printf("%.8lf\n", pp);
scanf("%d", &d1);
pp = maps[d1][d1];
double sum = 0.0;
while(pp >= 0.000000001)
{
sum += pp;
pp *= maps[d1][d1];
}
printf("%.8lf\n", sum + 1.0);
sum = 0.0;
scanf("%d", &d2);
pp = maps[d2][d2];
while(pp >= 0.000000001)
{
sum += pp;
pp *= maps[d2][d2];
}
printf("%.8lf\n", sum + 1.0);
return 0;
}
/*
*/
states, 1,2,3,...,N1,2,3,...,N.
We denote the time instants associated with state changes as t
= 1,2,...t=1,2,...,
and the actual state at time tt as a_{ij}=p=[s_{i}=j\
|\ s_{i-1}=i], 1\le i,j \le Naij=p=[si=j ∣ si−1=i],1≤i,j≤N.
For the special case of a discrete, first order, Markovchain, the probabilistic description for the current state (at time tt)
and the predecessor state is s_{t}st.
Furthermore we only consider those processes being independent of time, thereby leading to the set of state transition probability a_{ij}aij of
the form: with the properties a_{ij}
\geq 0aij≥0 and \sum_{i=1}^{N}
A_{ij} = 1∑i=1NAij=1.
The stochastic process can be called an observable Markovmodel. Now, let us consider the problem of a simple 4-state Markov model of weather. We assume that once a day (e.g., at noon), the weather is observed as being one of the following:
State 11:
snow
State 22:
rain
State 33:
cloudy
State 44:
sunny
The matrix A of state transition probabilities is:
A
= \{a_{ij}\}= \begin{Bmatrix} a_{11}&a_{12}&a_{13}&a_{14} \\ a_{21}&a_{22}&a_{23}&a_{24} \\ a_{31}&a_{32}&a_{33}&a_{34} \\ a_{41}&a_{42}&a_{43}&a_{44} \end{Bmatrix}A={aij}=⎩⎪⎪⎨⎪⎪⎧a11a21a31a41a12a22a32a42a13a23a33a43a14a24a34a44⎭⎪⎪⎬⎪⎪⎫
Given the model, several interestingquestions about weather patterns over time can be asked (and answered). We canask the question: what is the probability
(according to the given model) thatthe weather for the next k days willbe? Another interesting question we can ask: given that the model is in a knownstate, what is the expected number of consecutive days to stay
in that state?Let us define the observation sequence OOas O
= \left \{ s_{1}, s_{2}, s_{3}, ... , s_{k} \right \}O={s1,s2,s3,...,sk},
and the probability of the observation sequence OOgiven
the model is defined as p(O|model)p(O∣model).
Also, let the expected number of consecutive days to stayin state ii be E_{i}Ei.
Assume that the initial state probabilities p[s_{1}
= i] = 1, 1 \leq i \leq Np[s1=i]=1,1≤i≤N.
Bothp(O|model)p(O∣model)and E_{i}Ei are
real numbers.
Input Format
Line 11~44 forthe state transition probabilities. Line 55 for
the observation sequence O_{1}O1,
and line 66 for
the observation sequence O_{2}O2.
Line 77and
line 88 for
the states of interest to find the expected number of consecutive days to stay in these states.
Line 11: a_{11}\
a_{12}\ a_{13}\ a_{14}a11 a12 a13 a14
Line 22: a_{21}\
a_{22}\ a_{23}\ a_{34}a21 a22 a23 a34
Line 33: a_{31}\
a_{32}\ a_{33}\ a_{34}a31 a32 a33 a34
Line 44: a_{41}\
a_{42}\ a_{43}\ a_{44}a41 a42 a43 a44
Line 55: s_{1}\
s_{2}\ s_{3}\ ...\ s_{k}s1 s2 s3 ... sk
Line 66: s_{1}\
s_{2}\ s_{3}\ ...\ s_{l}s1 s2 s3 ... sl
Line 77: ii
Line 88: jj
Output Format
Line 11 andline 22 are
used to show the probabilities of the observation sequences O_{1}O1and O_{2}O2 respectively.
Line 33 and
line 44 are
for the expected number of consecutive days to stay in states ii and jj respectively.
Line 11: p[O_{1}
| model]p[O1∣model]
Line 22: p[O_{2}
| model]p[O2∣model]
Line 33: E_{i}Ei
Line 44: E_{j}Ej
Please be reminded that the floating number should accurate to 10^{-8}10−8.
样例输入
0.4 0.3 0.2 0.1 0.3 0.3 0.3 0.1 0.1 0.1 0.6 0.2 0.1 0.2 0.2 0.5 4 4 3 2 2 1 1 3 3 2 1 1 1 3 3 4 3 4
样例输出
0.00004320 0.00115200 2.50000000 2.00000000
题目来源
2017ACM-ICPC 亚洲区(南宁赛区)网络赛
题意:先给你4 * 4 的矩阵,表示天气 i 到天气 j 转变的概率,然后输入 k 个数字,以 ‘\n’ 表示输入结束,这 k 个数字的意思以
4 4 3 2 2 1 1 3 3
这组数字举例,其实就是天气从 4 转变为 4,然后从 4 转变为 3,然后从 3 转变为 2,然后从 2 转变为 2,然后从 2 转变为 1,然后从 1 转变为 1,然后从1 转变为 3,然后从3 转变为 3的概率是多少。
这样的输入数据有两组
然后输入两个数字 i 和 j ,这两个数字都表示天气的状况为 i 和 j 一直不变,不管天数增加多少,然后要你求一直不变的数学期望是多少。
附代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long LL;
///o(っ。Д。)っ AC万岁!!!!!!!!!!!!!!
const int maxn = 10;
double maps[maxn][maxn] = {};
int main()
{
for(int i = 1; i <= 4; i++)
{
for(int j = 1; j <= 4; j++)
{
scanf("%lf", &maps[i][j]);
}
}
double pp = 1.0;
int d1, d2;
char ch;
scanf("%d", &d1);
while(scanf("%d%c", &d2, &ch) != EOF)
{
pp *= maps[d1][d2];
d1 = d2;
if(ch == '\n') break;
}
printf("%.8lf\n", pp);
pp = 1.0;
scanf("%d", &d1);
while(scanf("%d%c", &d2, &ch) != EOF)
{
pp *= maps[d1][d2];
d1 = d2;
if(ch == '\n') break;
}
printf("%.8lf\n", pp);
scanf("%d", &d1);
pp = maps[d1][d1];
double sum = 0.0;
while(pp >= 0.000000001)
{
sum += pp;
pp *= maps[d1][d1];
}
printf("%.8lf\n", sum + 1.0);
sum = 0.0;
scanf("%d", &d2);
pp = maps[d2][d2];
while(pp >= 0.000000001)
{
sum += pp;
pp *= maps[d2][d2];
}
printf("%.8lf\n", sum + 1.0);
return 0;
}
/*
*/
相关文章推荐
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 F. Overlapping Rectangles(扫描线)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B. Train Seats Reservation
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛:L. The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 A Cache Simulator
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B题 离散化+贪心
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛:Train Seats Reservation
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛:Frequent Subsets Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 GSM Base Station Identification 线性变换||计算几何
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem 最长不下降序列
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 H A Cache Simulator
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L. The Heaviest Non-decreasing Subsequence Problem(最长非减子序列+思路)
- 计蒜客 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L. The Heaviest Non-decreasing Subsequence Problem(最长不下降子序列变形)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem (状态压缩)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛: M. Frequent Subsets Problem(状压)
- Frequent Subsets Problem 进制运算 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- Finding the Radius for an Inserted Circle 笛卡尔定理 - 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)英语阅读网络竞赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛: G. Finding the Radius for an Inserted Circle(笛卡尔定理)