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; 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 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 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.

Sample Input:

10

6666 5551 5552 1 7777 1 100

1234 5678 9012 1 0002 2 300

8888 -1 -1 0 1 1000

2468 0001 0004 1 2222 1 500

7777 6666 -1 0 2 300

3721 -1 -1 1 2333 2 150

9012 -1 -1 3 1236 1235 1234 1 100

1235 5678 9012 0 1 50

2222 1236 2468 2 6661 6662 1 300

2333 -1 3721 3 6661 6662 6663 1 100

Sample Output:

3

8888 1 1.000 1000.000

0001 15 0.600 100.000

5551 4 0.750 100.000

分析

参考并查集简析

  1. #include<iostream> //并查集的变形
  2. #include<vector>
  3. #include<set>
  4. #include<algorithm>
  5. #include<iomanip>
  6. using namespace std;
  7. struct family{
  8. int id, mid, fid, area, num;
  9. int cid[10];
  10. }data[1005];
  11. struct node{
  12. int id, people;
  13. double num, area;
  14. }ans[10000];
  15. vector<int> peo(10000,0);
  16. set<int> member, vec;
  17. int findfather(int c){
  18. while(c!=peo[c])
  19. c=peo[c];
  20. return c;
  21. }
  22. void Union(int a, int b){
  23. int m=findfather(a);
  24. int n=findfather(b);
  25. if(m<n)
  26. peo[n]=m;
  27. else
  28. peo[m]=n;
  29. }
  30. bool cmp(const node& n1, const node& n2){
  31. return (n1.area!=n2.area?n1.area>n2.area:n1.id<n2.id);
  32. }
  33. int main(){
  34. int n, cn, cnt=0;
  35. cin>>n;
  36. for(int i=0; i<10000; i++)
  37. peo[i]=i;
  38. for(int i=0; i<n; i++){
  39. cin>>data[i].id>>data[i].fid>>data[i].mid>>cn;
  40. member.insert(data[i].id);
  41. if(data[i].fid!=-1){
  42. member.insert(data[i].fid);
  43. Union(data[i].id, data[i].fid);
  44. }
  45. if(data[i].mid!=-1){
  46. member.insert(data[i].mid);
  47. Union(data[i].id, data[i].mid);
  48. }
  49. for(int j=0; j<cn; j++){
  50. cin>>data[i].cid[j];
  51. member.insert(data[i].cid[j]);
  52. Union(data[i].id, data[i].cid[j]);
  53. }
  54. cin>>data[i].num>>data[i].area;
  55. }
  56. for(int i=0; i<n; i++){
  57. int t=findfather(data[i].id);
  58. ans[t].id=t;
  59. ans[t].num+=data[i].num;
  60. ans[t].area+=data[i].area;
  61. vec.insert(t);
  62. }
  63. for(auto it=member.begin(); it!=member.end(); it++)
  64. ans[findfather(*it)].people++;
  65. for(auto it=vec.begin(); it!=vec.end(); it++){
  66. ans[*it].area=double(ans[*it].area/ans[*it].people);
  67. ans[*it].num=double(ans[*it].num/ans[*it].people);
  68. cnt++;
  69. }
  70. sort(ans, ans+10000, cmp);
  71. cout<<cnt<<endl;
  72. for(int i=0; i<cnt; i++)
  73. cout<<setw(4)<<setfill('0')<<ans[i].id<<" "<<ans[i].people<<" "<<setiosflags(ios::fixed)<<setprecision(3)<<ans[i].num<<" "<<ans[i].area<<endl;
  74. return 0;
  75. }

PAT 1114 Family Property的更多相关文章

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

    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 (并查集)

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

  4. 1114 Family Property (25 分)

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

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

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

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

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

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

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

  8. 1114 Family Property

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

  9. PAT A1114 Family Property

    用并查集处理每个家庭的信息,注意标记~ #include<bits/stdc++.h> using namespace std; ; bool visit[maxn]={false}; i ...

随机推荐

  1. oc66--代理模式应用2

    // // BabyProtocol.h #import <Foundation/Foundation.h> @class Baby; @protocol BabyProtocol < ...

  2. thinkphp的model的where条件的两种形式

    thinkphp的model的where查询时有两种形式. $model->field('id')->where('customer_num is null or customer_num ...

  3. CF 436D 最小生成树

    设一个开头的虚节点,然后建稠密图,O(n^2).使用prim.O(n^2),保存方案,没什么好说的. #include <string.h> #include <stdio.h> ...

  4. 记一次Oracle冷备恢复的过程

    一.故障来临 某日中午,市电意外中断,机房UPS电源由于负载过重而未接管供电,所有服务器全部重启...... 待所有服务器重启后,正在逐一检查设备和业务运行情况时,意外发生了.一台年代久远的HP PC ...

  5. linux的touch命令

    linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件. 1.命令格式: touch [选项]... 文件... 2.命令参数: -a    ...

  6. C#学习-处理Excel

    首先先了解下一个Excel文件的组成 1.一个Excel包含多个工作表(Sheet) 2.一个工作表(Sheet)包含多行(Row) 3.一行(Row)包含多个单元格(Cell)   如何判断一个单元 ...

  7. [ SCOI 2008 ] 着色方案

    \(\\\) \(Description\) 给出\(K\)种颜料各自的个数\(C_i\),每一个颜料只够涂一个格子,求将颜料用完,涂一排格子,每个格子只能涂一次的条件下,相邻两个格子的颜色互不相同的 ...

  8. Java中常用的操作PDF的类库

    iText iText是一个能够快速产生PDF文件的java类库.iText的java类对于那些要产生包含文本,表格,图形的只读文档是很有用的.它的类库尤其与java Servlet有很好的给合.使用 ...

  9. ScrollView在调试状态一点击就挂的原因(OnMouseActivate)

    这几天做的一个任务是做一个Dialog,需要在这个Dialog中添加一个自定义的CSrollvew类,但是遇到一个比较扯淡的问题,程序直接运行时可以的,调试状态下一点击CSrollview就挂了.而且 ...

  10. C# windform自定义控件的属性小知识

    word中的加粗变斜之类的一直让我以为是button,直到我接触了自定义控件,才发现实现这种机能最好的是CheckBox,然后我们在做一个系统的时候,这种控件有可能要用好多次,总不能在用一次的时候,就 ...