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 ...
随机推荐
- RESTful接口规范
一. 什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称,中文翻译为“表征状态转移” REST从资源的角 ...
- Echart实现多个y轴,坐标轴的个数及名称由后台传过来的json数据决定。
yAxis: function(){ var yAxis=[]; for(var i=0;i<legend1.length;i++){ var item={ name:legend1[i], t ...
- C语言常用关键字及运算符操作
1.关键字 (1)数据类型 char 1字节,8bit==256 int long,short unsgined ,signed 无符号为 ...
- three.js raycaster射线碰撞的坑 (当canvas大小 不是屏幕大小是解决拾取物体的办法)
这里只是记录一下坑,方便查阅,内容主要援引自:three.js Raycaster 射线拾取 canvas不占满整屏时射线拾取存在偏差 1. 世界坐标系: 世界坐标系位于屏幕的中心(0,0,0),往右 ...
- HTML DOM 事件对象
HTML DOM 事件对象 由 youj 创建,小路依依 最后一次修改 2016-08-04 HTML DOM 事件 HTML DOM 事件 HTML DOM 事件允许Javascript在HTML文 ...
- python any() all()
any() 函数用于判断给定的可迭代参数 iterable 是否全部为 False,则返回 False,如果有一个为 True,则返回 True. 元素除了是 0.空.FALSE 外都算 TRUE. ...
- 9.13 h5日记
9.13 面试题 为什么两个P出此案的效果不同,原因是 浏览器在解析第二个P的时候,因为字母没有空格,浏览器会认为这个单词没有打完,所以不会换行. 列表 ul ol dl li 1.无序列表 ul ( ...
- Win7自带功能,刻录光盘遇到的问题
Win7系统的可以使用系统自带有光盘刻录功能来刻录光盘. 把一张空白光盘放入刻录机,打开“计算机”窗口,双击刻录机图标,弹出“刻录光盘”对话框,选择刻录类型.这里有两个选项:一个是“类似于USB闪存驱 ...
- phpstorm+xdebug调试代码
1工具 #phpstorm 前面有文章介绍如何安装 #phpStudy 官网下的2018最新的安装包,php环境使用的也是最新的php7.0nts 2开启php Xdebug拓展 开启拓展,phpSt ...
- poj 2886 (线段树+反素数打表) Who Gets the Most Candies?
http://poj.org/problem?id=2886 一群孩子从编号1到n按顺时针的方向围成一个圆,每个孩子手中卡片上有一个数字,首先是编号为k的孩子出去,如果他手上的数字m是正数,那么从他左 ...