2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 A Weather Patterns(阅读理解)

亦凉 2022-06-08 11:39 312阅读 0赞

Weather Patterns

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 Nai**j​​=p=[si​​=jsi−1​​=i],1≤i,jN. 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}ai**j​​ of the form: with the properties a_{ij} \geq 0ai**j​​≥0 and \sum_{i=1}^{N} A_{ij} = 1∑​i=1​N​​Ai**j​​=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={ ai**j​​}=​⎩​⎪​⎪​⎨​⎪​⎪​⎧​​​a​11​​​a​21​​​a​31​​​a​41​​​​​a​12​​​a​22​​​a​32​​​a​42​​​​​a​13​​​a​23​​​a​33​​​a​43​​​​​a​14​​​a​24​​​a​34​​​a​44​​​​​⎭​⎪​⎪​⎬​⎪​⎪​⎫​​

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={ s​1​​,s​2​​,s​3​​,…,sk​​}, and the probability of the observation sequence OO given the model is defined as p(O|model)p(Omodel). 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[s​1​​=i]=1,1≤iN. Bothp(O|model)p(Omodel) and E_{i}Ei​​ are real numbers.

Input Format

Line 11~44 for the state transition probabilities. Line 55 for the observation sequence O_{1}O​1​​, and line 66 for the observation sequence O_{2}O​2​​. Line 77 and 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}a​11​​ a​12​​ a​13​​ a​14​​

Line 22: a_{21}\ a_{22}\ a_{23}\ a_{34}a​21​​ a​22​​ a​23​​ a​34​​

Line 33: a_{31}\ a_{32}\ a_{33}\ a_{34}a​31​​ a​32​​ a​33​​ a​34​​

Line 44: a_{41}\ a_{42}\ a_{43}\ a_{44}a​41​​ a​42​​ a​43​​ a​44​​

Line 55: s_{1}\ s_{2}\ s_{3}\ …\ s_{k}s​1​​ s​2​​ s​3​​ … sk​​

Line 66: s_{1}\ s_{2}\ s_{3}\ …\ s_{l}s​1​​ s​2​​ s​3​​ … sl​​

Line 77: ii

Line 88: jj

Output Format

Line 11 and line 22 are used to show the probabilities of the observation sequences O_{1}O​1​​ and O_{2}O​2​​ respectively. Line 33and 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[O​1​​∣model]

Line 22: p[O_{2} | model]p[O​2​​∣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​​.

样例输入

  1. 0.4 0.3 0.2 0.1
  2. 0.3 0.3 0.3 0.1
  3. 0.1 0.1 0.6 0.2
  4. 0.1 0.2 0.2 0.5
  5. 4 4 3 2 2 1 1 3 3
  6. 2 1 1 1 3 3 4
  7. 3
  8. 4

样例输出

  1. 0.00004320
  2. 0.00115200
  3. 2.50000000
  4. 2.00000000

题意:这题一点都不难,一道英语阅读理解题,读懂了你就会做了!这道题其实就是每天会有四种天气,分别是①下雪②下雨③多云④晴天,然后给你一个4*4的矩阵,这个矩阵的第i行第j个表示的就是从天气i到天气j的概率,然后接下来给你两个观察序列,问你天气完全按照这个观察序列上的顺序变化的概率是多少,第一天是任何天气的概率都为1。接下来再给你两个数i和j,问连续数天都是i天气和j天气的数学期望分别是多少。

思路:对于任意一个观察序列,我们只要按序列的顺序把两个天气之间变化的概率不断地乘就可以得出答案,比如说题目中的第二个序列,2 1 1 1 3 3 4,那么a[2][1]*a[1][1]*a[1][1]*a[1][3]*a[3][3]*a[3][4]就是答案。对于数学期望,我们就是求连续1天是i天气的概率+连续2天是i天气的概率+……+连续n天是i天气的概率,虽然这个n是无限大的,但是当加到后面之后这个概率会非常小可以忽视,所以我们只需要加1000个差不多就够了。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <string>
  5. #include <cstdlib>
  6. #include <cmath>
  7. #include <vector>
  8. #include <queue>
  9. #include <map>
  10. #include <algorithm>
  11. #include <set>
  12. #include <functional>
  13. using namespace std;
  14. typedef long long LL;
  15. typedef unsigned long long ULL;
  16. const int INF = 1e9 + 5;
  17. const int MAXN = 100000007;
  18. const int MOD = 1e9 + 7;
  19. const double eps = 1e-8;
  20. const double PI = acos(-1.0);
  21. LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a%b); }
  22. double MA[5][5];
  23. int main()
  24. {
  25. double ans, res;
  26. int x, y;
  27. char ch;
  28. for (int i = 1; i <= 4; i++)
  29. for (int j = 1; j <= 4; j++)
  30. scanf("%lf", &MA[i][j]);
  31. ans = 1;
  32. getchar();
  33. y = -1;
  34. while (scanf("%d", &x))
  35. {
  36. if (y == -1)
  37. {
  38. y = x;
  39. continue;
  40. }
  41. else
  42. {
  43. ans *= MA[y][x];
  44. y = x;
  45. }
  46. ch = getchar();
  47. if (ch != ' ')
  48. break;
  49. }
  50. printf("%.8f\n", ans);
  51. y = -1;
  52. ans = 1;
  53. while (scanf("%d", &x))
  54. {
  55. if (y == -1)
  56. {
  57. y = x;
  58. continue;
  59. }
  60. else
  61. {
  62. ans *= MA[y][x];
  63. y = x;
  64. }
  65. ch = getchar();
  66. if (ch != ' ')
  67. break;
  68. }
  69. printf("%.8f\n", ans);
  70. scanf("%d", &x);
  71. ans = 0;
  72. res = 1;
  73. for (int i = 1; i <= 1000; i++)
  74. {
  75. ans += res;
  76. res *= MA[x][x];
  77. }
  78. printf("%.8f\n", ans);
  79. scanf("%d", &x);
  80. ans = 0;
  81. res = 1;
  82. for (int i = 1; i <= 1000; i++)
  83. {
  84. ans += res;
  85. res *= MA[x][x];
  86. }
  87. printf("%.8f\n", ans);
  88. }

发表评论

表情:
评论列表 (有 0 条评论,312人围观)

还没有评论,来说两句吧...

相关阅读