• 2016级算法期末上机-I.难题·ModricWang's Fight with DDLs III


    1126 ModricWang's Fight with DDLs III

    思路

    由于题目中已经说明了时间经过了正无穷,因此初始位置是不重要的,并且每条边、每个点的地位是均等的。因此到达每个点的概率就是这个点的度数+1(可以停留就等于是有一条连向自己的边),最后的概率就是

    [frac{sum S中的点的度数}{sum 所有点的度数} ]

    时间复杂度(O(m)),空间复杂度(O(m))

    代码

    #include <iostream>
    #include <set>
    #include <vector>
    #include <iomanip>
    
    using namespace std;
    
    typedef unsigned long long ull;
    
    int main() {
    #ifdef ONLINE_JUDGE
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif
        ull n, m, k;
        set<ull> s;
    
        cin >> n >> m >> k;
        vector<ull> v(n, 1);
    
        auto tot = n + 2 * m, head = 0;
        for (auto i = 0; i < m; i++) {
            ull a, b;
            cin >> a >> b;
            v[a]++;
            v[b]++;
        }
    
        for (auto i = 0; i < k; i++) {
            ull p;
            cin >> p;
            head += v[p];
        }
        cout << fixed << setprecision(5) << 1.0 * head / tot << "
    ";
    }
    
  • 相关阅读:
    分类汇总统计mysql数据库一个字段中不同的记录的总和
    golang 基础知识4
    golang 基础知识3
    golang 基础知识2
    golang 基础知识1
    mysql 锁
    node child_process
    go get下载被墙的包
    mac 修改root的密码
    ali
  • 原文地址:https://www.cnblogs.com/AlvinZH/p/8215964.html
Copyright © 2020-2023  润新知