zoukankan      html  css  js  c++  java
  • 7-11 家庭房产(25 分)

    7-11 家庭房产(25 分)

    只能过前两个点

    #include<iostream>
    #include<cstdio>
    #include<vector>
    #include<algorithm>
    #include<cstring>
    #include<string>
    #include<map>
    #include<set>
    #include<queue>
    #include<iomanip>
    #include<stack>
    using namespace std;
    #define STDIN freopen("in.in", "r", stdin);freopen("out.out", "w", stdout);
    
    const int N = 10000+10;
    int fa[N];
    int n;
    int area[N], house[N], cnt[N];
    void init()
    {
        for (int i = 0; i <= 10000; i++) 
        {
            fa[i] = -1;
            cnt[i] = 1;
        }
    }
    int find(int x)
    {
        if (fa[x] == -1) return fa[x] = x;
        if (x == fa[x]) return x;
        return fa[x] = find(fa[x]);
    }
    
    void unite(int a, int b)
    {
        int f1 = find(a);
        int f2 = find(b);
        if (f1 <= f2) {
            fa[f2] = f1;
            house[f1] += house[f2];
            area[f1] += area[f2];
            cnt[f1] += cnt[f2];
        }
        else {
            fa[f1] = f2;
            house[f2] += house[f1];
            area[f2] += area[f1];
            cnt[f2] += cnt[f1];
        }
    }
    struct node{
        int v, cnt;
        double h, a;
    };
    bool cmp(node a, node b)
    {
        if (a.a == b.a) return a.v < b.v;
        return a.a > b.a;
    }
    int main()
    {
    //     STDIN
        cin >> n;
        init();
        for (int i = 1; i <= n; i++)
        {
            int k, f, m, kk;
            cin >> k >> f >> m >> kk;
            for (int j = 1; j <= kk; j++)
            {
                int x;
                cin >> x;
                if (find(x) != find(k))
                    unite(x, k);
            }
            int h, ar;
            cin >> h >> ar;
            area[find(k)] += ar;
            house[find(k)] += h;
            if (f!=-1 && find(k) != find(f))
                unite(k, f);
            if (m!=-1 && find(k) != find(m))
                unite(find(k), m);
        }
        int res = 0;
        vector<node> vec;
        for (int i = 1; i <= 10000; i++) {
            if (fa[i] == i) {
                res ++;
                vec.push_back({i, cnt[i], house[i]*1.0/cnt[i],area[i]*1.0/cnt[i]});
            }
        }
        cout << res << endl;
        sort(vec.begin(), vec.end(), cmp);
        for (auto &i : vec)
        {
            printf("%04d %d %.3f %.3f
    ", i.v, i.cnt, i.h, i.a);
        }
    }    
  • 相关阅读:
    安装第三方工具包
    C#判断联网状态
    SQL Server 字符串函数
    SharePoint 计时器服务无法启动
    为SharePoint 2010中的FBA创建自定义登录页面
    document对象
    Moss 几个编程技巧
    【Sharepoint】CSS与Master Page的开发与部署
    自定义和扩展 SharePoint 2010 Server 功能区
    自定义ASP.NET WebApplication中调用SharePoint2010的对象
  • 原文地址:https://www.cnblogs.com/hulian425/p/14039106.html
Copyright © 2011-2022 走看看