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. solrj 测试连接 6.6.5solr集群

    我开始环境是 linux上是6.6.5  pom也是6.6.5 按照学习视频的demo,他用的是4点几的solr,我换成了6点几的,没有CloudSolrServer  只有CloudSolrClie ...

  2. JFinal Web开发学习(四)数据库连接与自动生成model

    1.新建数据库jfinal_test,user表 /* Navicat MySQL Data Transfer Source Server : . Source Server Version : 50 ...

  3. BitCoinCore配置文件解读

    bitcoin.conf 配置文件 除了 -datadir 和 -conf 以外的所有命令行参数都可以通过一个配置文件来设置,而所有配置文件中的选项也都可以在命令行中设置.命令行参数设置的值会覆盖配置 ...

  4. C# 一个数组未赋值引发的错误

    在电脑前又是一天,后来脑子也糊里糊涂,可能是基础还不牢固,设置断点,找了找问题才发现数组定义出了问题, 我是这样定义数组的,string[] auths ; string auths=new stri ...

  5. Android开发之使用GridView+仿微信图片上传功能(附源代码)

    前言:如果转载文章请声明转载自:https://i.cnblogs.com/EditPosts.aspx?postid=7419021  .另外针对有些网站转载本人的文章结果源码链接不对的问题,本人在 ...

  6. Spring MVC(一)Servlet 2.x 规范在 Spring MVC 中的应用

    Spring MVC(一)Servlet 2.x 规范在 Spring MVC 中的应用 Spring 系列目录(https://www.cnblogs.com/binarylei/p/1019869 ...

  7. Maximum Size Subarray Sum Equals k LT325

    Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If t ...

  8. Java开发环境安装配置

    电脑配置:Win7 64位 JDK1.8+Apache Tomcat8.5.4 下载JDK1.8 全名: Java SE Development Kit 8u151,下载最新稳定版本 下载地址:htt ...

  9. .NET发送邮件的方法

    整理一下,在.NET中发送邮件的一个方法,代码如下: public static string Net_Email(string strSendto, string strCC, string str ...

  10. php实现MySQL两库对比升级版

    define('DATABASE1', 'db1'); $dbi1 = new DbMysql; $dbi1->dbh = 'mysql://root:password@127.0.0.1/'. ...