ZOJ 2853

原题链接

描述

Evolution is a long, long process with extreme complexity and involves many species. Dr. C. P. Lottery is currently investigating a simplified model of evolution: consider that we have N (2 <= N <= 200) species in the whole process of evolution, indexed from 0 to N -1, and there is exactly one ultimate species indexed as N-1. In addition, Dr. Lottery divides the whole evolution process into M (2 <= M <= 100000) sub-processes. Dr. Lottery also gives an 'evolution rate' P(i, j) for 2 species i and j, where i and j are not the same, which means that in an evolution sub-process, P(i, j) of the population of species i will transform to species j, while the other part remains unchanged.
Given the initial population of all species, write a program for Dr. Lottery to determine the population of the ultimate species after the evolution process. Round your final result to an integer.

输入

The input contains multiple test cases!
Each test case begins with a line with two integers N, M. After that, there will be a line with N numbers, indicating the initial population of each species, then there will be a number T and T lines follow, each line is in format "i j P(i,j)" (0 <= P(i,j) <=1).
A line with N = 0 and M = 0 signals the end of the input, which should not be proceed.

输出

For each test case, output the rounded-to-integer population of the ultimate species after the whole evolution process. Write your answer to each test case in a single line.

注意

There will be no 'circle's in the evolution process.
E.g. for each species i, there will never be a path i, s1, s2, ..., st, i, such that P(i,s1) <> 0, P(sx,sx+1) <> 0 and P(st, i) <> 0.
The initial population of each species will not exceed 100,000,000.
There're totally about 5 large (N >= 150) test cases in the input.

举例

Let's assume that P(0, 1) = P(1, 2) = 1, and at the beginning of a sub-process, the populations of 0, 1, 2 are 40, 20 and 10 respectively, then at the end of the sub-process, the populations are 0, 40 and 30 respectively.

样例输入

2 3
100 20
1
0 1 1.0
4 100
1000 2000 3000 0
3
0 1 0.19
1 2 0.05
0 2 0.67
0 0

样例输出

120
0

思路

第一关是读懂题意,我这种英语渣看了半天才看懂。
看懂题意后就很简单了,构建矩阵,然后标准的矩阵快速幂,注意最后取整就好。
顺便这里一个小插曲,我的devcpp报段错误,似乎是我把矩阵开太大的原因,但是数据范围就这么大,提交之后却AC了,也是尴尬。

代码

#include <cstdio>
#include<cstring>
#define ll long long
#define maxn 201
using namespace std;

int k;
int n;

struct Mat
{
    double f[maxn][maxn];
    void cls(){memset(f, 0, sizeof(f));}//全部置为0 
    Mat() {cls();}
    friend Mat operator * (Mat a, Mat b)
    {
        Mat res;
        for(int i = 0; i < n; i++) for(int j = 0; j < n; j++)
            for(int k = 0; k < n; k++)
                res.f[i][j] += a.f[i][k] * b.f[k][j];
        return res;
    }
};

Mat quick_pow(Mat a)  
{  
    Mat ans;
    for(int i = 0; i < n; i++) ans.f[i][i] = 1;
    int b = k;
    while(b != 0)  
    {
        if(b & 1) ans = ans * a;
        b >>= 1;
        a = a * a;
    }
    return ans;  
}

int main()
{
    while(~scanf("%d %d", &n, &k))
    {
        if(n + k == 0) break;
        Mat A, B;
        for(int i = 0; i < n; i++) A.f[i][i] = 1;
        for(int i = 0; i < n; i++)
            scanf("%lf", &B.f[i][0]);
        int t; scanf("%d", &t);
        while(t--)
        {
            int x, y;
            double p;
            scanf("%d %d %lf", &x, &y, &p);
            A.f[x][x] -= p;
            A.f[y][x] += p;
        }
        A = quick_pow(A);
        B = A * B;
        printf("%.0lf\n", B.f[n-1][0]);
    }
    return 0;
}

转载于:https://www.cnblogs.com/HackHarry/p/8399047.html

### Windows 上安装 Ubuntu 子系统的步骤指南 #### 准备工作 为了在 Windows 上安装 Ubuntu 子系统,需要先启用 **Windows Subsystem for Linux (WSL)** 功能。这可以通过 PowerShell 或其他管理员工具来实现。 #### 启用 WSL 和虚拟机平台功能 打开 PowerShell 并以管理员身份运行以下命令: ```powershell dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart ``` 执行上述命令后,需重启计算机以应用更改[^2]。 #### 设置 WSL 版本 目前有两种版本的 WSL 可供选择:WSL 1 和 WSL 2。推荐使用性能更优的 WSL 2。设置默认版本为 WSL 2 的方法如下: ```powershell wsl --set-default-version 2 ``` #### 安装 Ubuntu 发行版 通过 Microsoft Store 下载所需的 Ubuntu 发行版。以下是具体操作流程: 1. 打开 Microsoft Store 应用程序。 2. 搜索 “Ubuntu”,可以选择最新版本或其他特定版本(如 Ubuntu 20.04 LTS)。 3. 单击“获取”按钮下载并安装发行版。 #### 初始化和配置 Ubuntu 用户账户 完成安装后,在开始菜单中找到已安装的 Ubuntu 应用程序并启动它。首次启动时会自动初始化子系统,并提示创建一个新的 UNIX 用户名和密码。这些凭据将用于登录到 WSL 中的 Ubuntu 命令行界面[^1]。 #### 验证文件共享功能 一旦成功安装并配置好 Ubuntu 子系统,可以验证宿主机与 WSL 文件之间的互访能力。例如,使用 `df -h` 查看磁盘挂载情况,默认情况下宿主机上的驱动器会被映射至 `/mnt/` 路径下[^3]。 #### 测试环境 最后一步是测试新安装好的 Ubuntu 是否正常运作以及能否满足日常开发需求。尝试更新包列表并升级现有软件包: ```bash sudo apt update && sudo apt upgrade -y ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值