1114 Family Property
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 Child1⋯Childk Mestate 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; Childi's are the ID
's of his/her children; Mestate 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
AVGsets AVGarea
where ID
is the smallest ID in the family; M
is the total number of family members; AVGsets is the average number of sets of their real estate; and AVGarea 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的更多相关文章
- 1114 Family Property (25 分)
1114 Family Property (25 分) This time, you are supposed to help us collect the data for family-owned ...
- PAT甲级1114. Family Property
PAT甲级1114. Family Property 题意: 这一次,你应该帮我们收集家族财产的数据.鉴于每个人的家庭成员和他/她自己的名字的房地产(房产)信息,我们需要知道每个家庭的规模,以及他们的 ...
- PAT 1114 Family Property[并查集][难]
1114 Family Property(25 分) This time, you are supposed to help us collect the data for family-owned ...
- PAT甲级——1114 Family Property (并查集)
此文章同步发布在我的CSDN上https://blog.csdn.net/weixin_44385565/article/details/89930332 1114 Family Property ( ...
- PAT 1114 Family Property
This time, you are supposed to help us collect the data for family-owned property. Given each person ...
- PAT (Advanced Level) 1114. Family Property (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT甲题题解-1114. Family Property (25)-(并查集模板题)
题意:给出每个人的家庭成员信息和自己的房产个数与房产总面积,让你统计出每个家庭的人口数.人均房产个数和人均房产面积.第一行输出家庭个数,随后每行输出家庭成员的最小编号.家庭人口数.人均房产个数.人均房 ...
- 【PAT甲级】1114 Family Property (25分)(并查集)
题意: 输入一个正整数N(<=10000),接着输入N行每行包括一个人的ID和他双亲的ID以及他的孩子数量和孩子们的ID(四位整数包含前导零),还有他所拥有的房产数量和房产面积.输出一共有多少个 ...
- pat甲级1114
1114 Family Property(25 分) This time, you are supposed to help us collect the data for family-owned ...
随机推荐
- grep与正则表达式的使用
正则表达式以及grep的使用 grep是一种文本过滤工具(模式:pattern)基本使用用法如下: grep [option] PATTERN FILE grep [OPTIONS] [-e PATT ...
- go语言path包和filepath包的学习与使用
path包的使用 package main; import ( "fmt" "path" ) //go语言path包的学习 func main() { //返回 ...
- 如何去掉IE文本框后的那个X css代码
在IE10以上版本中,页面上的文本框控件在输入文字时候会被自动加上一个X.但是IE这个自作聪明的功能有时候会让我们的页面爆掉,比如当文本框宽度过小,X显示不下时候会顶掉你的文本. 要隐藏这个X可以用I ...
- Gulp应用场景
转自:Gulp教程之:Gulp能做什么,前端装逼为何要用它 我们先说说 平时web开发遇到的一些场景 和 苦恼无奈的情况: JavaScript和CSS的版本问题 我们都知道 JavaScript ...
- spring boot 整合 RabbitMq (注解)
1.增加rabbitmq的依赖包 <!-- ampq 依赖包 --> <dependency> <groupId>org.springframework.boot& ...
- BZOJ 3007 [SDOI2012]拯救小云公主 - 对偶图 + 并查集
Solution 答案具有单调性, 显然可以二分答案. 有两个注意点 : 英雄是可以随便走的, 也就是不是网格图... 还有坐标不能小于$1$ QAQ 开始时英雄在左下角, 公主在右上角, 我们反过来 ...
- powershell上传证书
https://www.cnblogs.com/threestone/p/4001632.html powershell上传证书
- Vim on Mac Terminal
2018-04-15 在Python 里面加标注, 发现Vim强大的两种用法, 比如要在1-5行加标注: 1. 用寻找和替代(basic search and replace),:1, 5s/^/# ...
- docker下安装tomcat
一,查看tomcat镜像 [root@icompany ~]# docker search tomcat INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED ...
- java连接数据库以及连接参数格式
//链接数据库代码部分 下面具有连接的基本参数可以对照修改(参数存放在file下面的database.properties下面) //参数存放在file下面的database.properties下 ...