zoukankan      html  css  js  c++  java
  • hdoj1437 -- 天气情况

    天气情况

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 707    Accepted Submission(s): 285


    Problem Description
    如 果我们把天气分为雨天,阴天和晴天3种,在给定各种天气之间转换的概率,例如雨天转换成雨天,阴天和晴天的概率分别为0.4,0.3,0.3.那么在雨天 后的第二天出现雨天,阴天和晴天的概率分别为0.4,0.3,0.3.现在给你今天的天气情况,问你n天后的某种天气出现的概率.
     
    Input
    我们这里假设1,2,3分别代表3种天气情况,Pij表示从i天气转换到j天气的概率.
    首先是一个数字T表示数据的组数.
    每组数据以9个数开始分别是P11,P12,P13,……,P32,P33,接着下一行是一个数字m,表示提问的次数。每次提问有3个数据,i,j,n,表示过了n天从i天气情况到j天气情况(1<=i,j<=3 1<=n<=1000)。
     
    Output
    根据每次提问输出相应的概率(保留3位小数)。
     
    Sample Input
    1 0.4 0.3 0.3 0.2 0.5 0.3 0.1 0.3 0.6 3 1 1 1 2 3 1 1 1 2
     
    Sample Output
    0.400 0.300 0.250 Hint:如果GC提交不成功,可以换VC试试
     
    Author
    xhd
     
    Source
     
    Recommend
    lcy   |   We have carefully selected several similar problems for you:  1757 3117 1427 3483 3519
     
    #include <cstdio>
    #include <cstring>
    double a[4][4][1100], p[4][4];
    void deal()
    {
        memset(a, 0.0, sizeof(a));
        for(int i=1; i<=3; i++)
            for(int j=1; j<=3; j++)
                a[i][j][1]=p[i][j];
                
        for(int i=2; i<=1001; i++)
            for(int j=1; j<=3; j++)
                for(int k=1; k<=3; k++)
                    for(int l=1; l<=3; l++)
                        a[j][k][i] += a[j][l][i-1]*p[l][k];   //例如: 0--> 3: 0-->0-->3,0-->1-->3, 0-->2-->3;  
    }
    int main()
    {
        int m; scanf("%d", &m);
        while(m--)
        {
            for(int i=1; i<=3; i++)
                for(int j=1; j<=3; j++)
                    scanf("%lf", &p[i][j]);
            deal(); 
            int n; scanf("%d", &n); 
            while(n--)
            {
                int x, y, z;
                scanf("%d%d%d", &x, &y, &z);
                printf("%.3lf
    ", a[x][y][z]);
            }
        }
        return 0;
    }

    上述deal() ;

    #include <stdio.h>
    #define N 1010
    int main()
    {
        double p[4][4], f[1010][3];
        int Q; scanf("%d", &Q);
        while(Q--)
        {    
            scanf ("%lf %lf %lf %lf %lf %lf %lf %lf %lf",&p[1][1],&p[1][2],&p[1][3],&p[2][1],&p[2][2],&p[2][3],&p[3][1],&p[3][2],&p[3][3]);          
            int t; scanf("%d", &t); 
            while(t--)
            {
                int a, b, c;
                scanf("%d %d %d", &a, &b, &c);
                f[1][0] = p[a][1];
                f[1][1] = p[a][2];
                f[1][2] = p[a][3]; 
                for(int i=2; i<=c; i++)
                {
                    f[i][0] = f[i-1][0] * p[1][1] + f[i-1][1] * p[2][1] + f[i-1][2]*p[3][1] ;
                    f[i][1] = f[i-1][0] * p[1][2] + f[i-1][1] * p[2][2] + f[i-1][2]*p[3][2] ;
                    f[i][2] = f[i-1][0] * p[1][3] + f[i-1][1] * p[2][3] + f[i-1][2]*p[3][3] ; 
                }
                printf("%.3lf
    ", f[c][b-1]);
            }
        }
        return 0;
    }
  • 相关阅读:
    JS与Android交互
    win10 死机 无响应
    clientdataset.open 报错 Name not unique in this context
    WIN10 常用bug解决办法
    关闭win10 自动更新 及蓝屏解决办法
    delphi 调用Webservice 引入wsdl 报错 document empty
    C# 类库调试 启动外部程序无法调试
    ADOQuery.Parameters: Property Parameters does not exist
    delphi android 自动升级
    不死僵尸木马lpt7.asp.asp与lpt5.cnzzz.asp的删除方法
  • 原文地址:https://www.cnblogs.com/soTired/p/5348448.html
Copyright © 2011-2022 走看看