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));
}
}

最新文章

  1. sqL编程篇(三) 游标与存储过程
  2. 向ES6靠齐的Class.js
  3. ANDROID开发中注意不同手机CPU架构对SO文件的不同需求。
  4. a chip multiprocessor
  5. 分享50款 Android 移动应用程序图标【下篇】
  6. jQuery extend 实现代码封装
  7. Hbase中的BloomFilter(布隆过滤器)
  8. QT中给各控件增加背景图片(可缩放可旋转)的几种方法
  9. struts2:异常处理
  10. Virtual Environments for mac
  11. jquery加载页面的方法
  12. Core Java Volume I — 3.1. A Simple Java Program
  13. signed char、unsigned char
  14. _tkinter.TclError: no display name and no $DISPLAY environment variable
  15. systemd学习
  16. OneHotEncoder独热编码和 LabelEncoder标签编码
  17. HDU4514 湫湫系列故事——设计风景线 ——树的直径/树形dp+判环
  18. 微信小程序高级基础
  19. k-center问题-学习
  20. (原)torch中提示Unwritable object &lt;userdata&gt; at &lt;?&gt;.callback.self.XXX.threads.__gc__

热门文章

  1. 安装opencv2.4.9
  2. props传递数据
  3. Android开发之自定义Dialog简单实现
  4. std::move 移动对象资源
  5. angular2.0学习笔记5.关于组件
  6. tmp下莫名其妙生成root权限的缓存文件
  7. Homestead 修改 Homestead.yaml 文件后 vagrant up 报错的问题
  8. @1-4使用Xpath解析豆瓣短评
  9. 转:Struts2返回JSON数据的具体应用范例
  10. Linux配置nodejs