1114 Family Property(25 分)

并查集
注意在计算totsets时遍历a数组就可以,计算人数是从0到maxn遍历,因为不是每一个人有财产和土地

#include
#include
using namespace std;
const int maxn = 1e5 + 10;
int father[maxn];
bool isroot[maxn];
struct node {
    int id;
    double mestate, area;
}a[maxn];
int findfather(int x)
{
    int a = x;
    while (x != father[x])x = father[x];
    while (a != father[a])
    {
        int z = a;
        a = father[a];
        father[z] = x;
    }
    return x;
}
void Union(int x, int y)
{
    int fx = findfather(x);
    int fy = findfather(y);
    if (fx != fy)
    {
        if (fx < fy)father[fy] = fx;
        else father[fx] = fy;
    }
}

struct fam {
    int m, id;
    double totsets, totarea;
    bool valid;
    bool operator<(const fam&x)const
    {
        return valid == true && x.valid == true ? totarea / m == x.totarea / x.m ? idx.totarea / x.m : valid > x.valid;
    }
}ans[maxn];
int main()
{
    int n;
    for (int i = 0; i < maxn; i++)father[i] = i;
    scanf("%d", &n);
    for(int i=0;i

你可能感兴趣的:(1114 Family Property(25 分))