This time, you are supposed to help us collect the data for family-owned property. Given each person's family members, and the estate(房产)info under his/her own name, we need to know the size of each family, and the average area and number of sets of their real estate.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤1000). Then N lines follow, each gives the infomation of a person who owns estate in the format:

ID Father Mother k Child​1​​⋯Child​k​​ M​estate​​ Area

where ID is a unique 4-digit identification number for each person; Father and Mother are the ID's of this person's parents (if a parent has passed away, -1 will be given instead); k (0≤k≤5) is the number of children of this person; Child​i​​'s are the ID's of his/her children; M​estate​​ is the total number of sets of the real estate under his/her name; and Area is the total area of his/her estate.

Output Specification:

For each case, first print in a line the number of families (all the people that are related directly or indirectly are considered in the same family). Then output the family info in the format:

ID M AVG​sets​​ AVG​area​​

where ID is the smallest ID in the family; M is the total number of family members; AVG​sets​​ is the average number of sets of their real estate; and AVG​area​​ is the average area. The average numbers must be accurate up to 3 decimal places. The families must be given in descending order of their average areas, and in ascending order of the ID's if there is a tie.

知识点:并查集

注意并查集的写法

 #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = ; int ManSet[maxn];
int Property[maxn][];
int used[maxn];
//set<int> bool cmp(int a,int b){
if(Property[a][]/(-ManSet[a]+0.0)==Property[b][]/(-ManSet[b]+0.0)){
return a<b;
}
return Property[a][]/(-ManSet[a]+0.0)>Property[b][]/(-ManSet[b]+0.0);
} int Find(int v){
if(ManSet[v]<=-){
return v;
}
return ManSet[v] = Find(ManSet[v]);
} int Unite(int n1, int n2){ if(n1<n2){
ManSet[n1] += ManSet[n2];
ManSet[n2] = n1;
return n1;
}else{
ManSet[n2] += ManSet[n1];
ManSet[n1] = n2;
return n2;
}
} int main(int argc, char *argv[]) {
int n;
fill(ManSet,ManSet+maxn,-);
fill(Property[],Property[]+maxn*,);
fill(used,used+maxn,); scanf("%d",&n);
int man,fa,mo,k,tmpc,m,area;
for(int i=;i<n;i++){
//printf("\n");
scanf("%d %d %d",&man,&fa,&mo);
used[man] = used[fa] = used[mo] = ;
//printf("\n. %d %d,%d\n",Find(man),i,n);
man = Find(man); //printf("%d ",man);
if(fa!=-){
fa = Find(fa);
if(fa!=man){
man = Unite(man,fa); //printf("%d ",man);
}
}
man = Find(man);
if(mo!=-){
mo = Find(mo);
if(mo!=man){
man = Unite(man,mo);//printf("%d ",man);
}
}
scanf("%d",&k);
for(int j=;j<k;j++){
scanf("%d",&tmpc);
used[tmpc] = ;
tmpc = Find(tmpc);
man = Find(man);
if(man!=tmpc){
man = Unite(man,tmpc);//printf("%d ",man);
}
}
scanf("%d %d",&m,&area);
Property[man][] += m;
Property[man][] += area;
}
for(int i=;i<maxn;i++){
if(used[i]==&&ManSet[i]>&&Property[i][]>){
int an = Find(i);
Property[an][]+=Property[i][];
Property[an][]+=Property[i][];
}
}
vector<int> list;
for(int i=;i<maxn;i++){
if(used[i]==&&ManSet[i]<){
list.push_back(i);
//printf("%04d %d %.3f %.3f\n",i,(-ManSet[i]),Property[i][0]/(-ManSet[i]+0.0),Property[i][1]/(-ManSet[i]+0.0));
}
}
sort(list.begin(), list.end(), cmp);
printf("%d\n",list.size());
for(int i=;i<list.size();i++){
printf("%04d %d %.3f %.3f\n",list[i],(-ManSet[list[i]]),Property[list[i]][]/(-ManSet[list[i]]+0.0),Property[list[i]][]/(-ManSet[list[i]]+0.0));
}
}

1114 Family Property的更多相关文章

  1. 1114 Family Property (25 分)

    1114 Family Property (25 分) This time, you are supposed to help us collect the data for family-owned ...

  2. PAT甲级1114. Family Property

    PAT甲级1114. Family Property 题意: 这一次,你应该帮我们收集家族财产的数据.鉴于每个人的家庭成员和他/她自己的名字的房地产(房产)信息,我们需要知道每个家庭的规模,以及他们的 ...

  3. PAT 1114 Family Property[并查集][难]

    1114 Family Property(25 分) This time, you are supposed to help us collect the data for family-owned ...

  4. PAT甲级——1114 Family Property (并查集)

    此文章同步发布在我的CSDN上https://blog.csdn.net/weixin_44385565/article/details/89930332 1114 Family Property ( ...

  5. PAT 1114 Family Property

    This time, you are supposed to help us collect the data for family-owned property. Given each person ...

  6. PAT (Advanced Level) 1114. Family Property (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...

  7. PAT甲题题解-1114. Family Property (25)-(并查集模板题)

    题意:给出每个人的家庭成员信息和自己的房产个数与房产总面积,让你统计出每个家庭的人口数.人均房产个数和人均房产面积.第一行输出家庭个数,随后每行输出家庭成员的最小编号.家庭人口数.人均房产个数.人均房 ...

  8. 【PAT甲级】1114 Family Property (25分)(并查集)

    题意: 输入一个正整数N(<=10000),接着输入N行每行包括一个人的ID和他双亲的ID以及他的孩子数量和孩子们的ID(四位整数包含前导零),还有他所拥有的房产数量和房产面积.输出一共有多少个 ...

  9. pat甲级1114

    1114 Family Property(25 分) This time, you are supposed to help us collect the data for family-owned ...

随机推荐

  1. JFinal Web开发学习(二)目录、架构、package设计

    package分类 config是JFinal的项目配置 controller是控制器 handler可以设置全局处理器,例如判断用户请求中是否直接请求 FreeMarker的模板文件ftl或者htm ...

  2. MVC报错:找到多个与名为“Home”的控制器匹配的类型。

    错误原因是:在根目录中的Controller中有HomeController,而在Areas中也有一个HomeController,只是他们的命名空间不一样. 这样的话,只需要在对应的路由注册中加入命 ...

  3. 学习knockoutjs轻量级的MVVM框架

    教程:knockoutjs介绍 http://www.w3cfuns.com/forum.php?mod=viewthread&tid=5598714 MVVM架构~knockoutjs实现简 ...

  4. c#设计模式3抽象工厂模式(Abstract Factory)

    #region 坦克系列 abstract class Tank { abstract public void Go(); } /// <summary> /// 越野车 /// < ...

  5. 21.Mysql Server优化

    21.优化Mysql Server21.1 Mysql体系结构概览Mysql由Mysql Server层和存储引擎层组成.Mysql实例由一组后台进程.一写内存块和若干服务线程组成.Mysql后台进程 ...

  6. hdu 5692(dfs+线段树) Snacks

    题目http://acm.hdu.edu.cn/showproblem.php?pid=5692 题目说每个点至多经过一次,那么就是只能一条路线走到底的意思,看到这题的格式, 多个询问多个更新, 自然 ...

  7. Android.Tools.Summary

    Android平台上工具的总结 每个工具的详细使用和深入理解参考每个工具相关的blog. 1. Android SDK中提供的工具 http://developer.android.com/tools ...

  8. GM Tech 2 works with Hummer Yes or No

    This is about GM Tech 2 scan tool for Hummer troubleshooting and programming. Can I have a cheap Tec ...

  9. oracle主键修改&设置某一字段可以为null

    1.oracle主键修改 1.1)首先查看需要修改的表的主键名,默认的情况下,数据库会自动分配 select * from user_cons_columns where table_name='表名 ...

  10. 转录本组装软件StringTie的使用说明

    转录本组装软件StringTie的使用说明 StringTie 转录本组装软件StringTie的使用说明 转录组分析流程 HISTA + StringTie 组合.其Protocol 发表在Natu ...