//给定 id id的父亲 id的母亲(-1表示过世) k id的k个孩子 房产的数量 房产的面积
//求每个家庭(用最小的id存储)房产的总数 平均房产数量和面积(平均保留三位)
//排序:平均面积的降序 tie id的增序
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct node0 {int id, fid, mid, num, area;int cid[10];
}data[1001];
struct node {int id, people;double num, area;bool flag = false;
}ans[10000];
vector<int> father(10000);//存放i的父节点的位置
vector<bool> visited(10000);
int find(int x){//找到x的根节点while (x != father[x])x = father[x];return x;
}
void Union(int a, int b){a = find(a);b = find(b);if(a > b) father[a] = b;else father[b] = a;
}
bool cmp(node &a, node &b){if(a.area == b.area) return a.id < b.id;else return a.area > b.area;
}int main(){int n, k, cnt = 0;cin >> n;for (int i = 0; i < 10000; i++)father[i] = i;//初始化每一个节点的父节点为本身for (int i = 0; i < n; i++) {cin >> data[i].id >> data[i].fid >> data[i].mid >> k;visited[data[i].id] = true;//记录存在该结点if (data[i].fid != -1) {visited[data[i].fid] = true;Union(data[i].fid, data[i].id);}if (data[i].mid != -1) {visited[data[i].mid] = true;Union(data[i].mid, data[i].id);}for (int j = 0; j < k; j++) {cin >> data[i].cid[j];visited[data[i].cid[j]] = true;Union(data[i].cid[j], data[i].id);}cin >> data[i].num >> data[i].area;}for (int i = 0; i < n; i++) {int id = find(data[i].id);//找祖先节点ans[id].id = id;//祖先节点为答案节点ans[id].num += data[i].num;//同一家族的房子数加和ans[id].area += data[i].area;ans[id].flag = true;//记录存在该答案结点}for (int i = 0; i < 10000; i++) {if(visited[i]) ans[find(i)].people++;if(ans[i].flag) cnt++;}for (int i = 0; i < 10000; i++) {if(ans[i].flag){ans[i].num = ans[i].num * 1.0 / ans[i].people;ans[i].area = ans[i].area * 1.0 / ans[i].people;}}sort(ans, ans + 10000, cmp);cout << cnt << endl;for (int i = 0; i < cnt; i++) {printf("%04d %d %.3lf %.3lf\n", ans[i].id, ans[i].people, ans[i].num, ans[i].area);}return 0;
}

1114. Family Property (25)相关推荐

  1. C++学习之路 | PTA(甲级)—— 1114 Family Property (25分)(带注释)(并查集)(精简)

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

  2. 1114. Family Property (25)-PAT甲级真题(并查集)

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

  3. 1114 Family Property (25分) (并查集) 复杂题 经典并查集

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

  4. 1114 Family Property (25 分)【难度: 中/ 知识点: 并查集】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805356599820288 挺好的一个并查集,先读入然后再处理.注意:在 ...

  5. PAT甲级1114 Family Property:[C++题解]结构体、并查集、测试点3、4、5有问题的进来!!

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析: 先建边.读入每家的信息,在本人和父母(如果有的话),本人与子女(如果有的话)之间分别建边.边用结构体来存,边记录两个端点. 遍历每条 ...

  6. 【PAT】A1114 Family Property (25 point(s))

    文章目录 A1114 Family Property (25 point(s)) Input Specification: Output Specification: Sample Input: Sa ...

  7. PAT 1114 Family Property 并查集

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

  8. PAT甲级题目翻译+答案 AcWing(并查集)

    1013 Battle Over Cities (25 分) 题意 :给图,问去掉所询问的一个点后,需要添加多少条边可以使图连通,N<1000N<1000N<1000 思路 :并查集 ...

  9. 刷PAT甲级的各题思路、细节以及遇到的问题记录

    1001 A+B Format (20分) 因为一定会用到字符串,而string非常好用,但是用的时候一定要注意不能越界访问,否则会在运行时出现abort() has been called. 100 ...

最新文章

  1. python使用fpdf创建页眉、页脚并嵌入图片
  2. python3占位符 中文_WxString:有没有使用Python 3-占位符实现字符串格式化的C/C++代码?...
  3. 使用MAT做jvm的GC Roots溯源
  4. CodeForces - 1455E Four Points(数学+几何)
  5. Materials about design pattern
  6. pr下雪下雨_图像增强:下雨,下雪。 如何修改照片以训练自动驾驶汽车
  7. php设计模式之单例模式 1
  8. 03-20 专项测试-APP 启动性能分析
  9. 让IE支持Css3属性(圆角、阴影、渐变)
  10. 施耐德 m340 编程手册_施耐德PLC漏洞历险记
  11. MacOS系统离线安装包11.x-12.x
  12. 20200115每日一句
  13. 微信小游戏源码及H5开源小程序游戏源码1000套
  14. CIF/4CIF/QCIF/D1
  15. pythonexcel操作总结_python中常见关于Excel表格读写操作
  16. 蚀刻后残留物和光刻胶去除技术
  17. Azure - AD B2C自定义策略和身份体验框架
  18. MIMIC III数据集详细介绍
  19. 2009年中国十大科技进展新闻
  20. 银行离岸汇款客户交易预测

热门文章

  1. 大数据时代的创新者们
  2. 零基础Java学习之包(Package)
  3. Numpy生成二项分布随机数
  4. 非平衡数据处理方式与评估
  5. 解决写入InfluxDB时,报unbalanced quotes的问题
  6. C++ 优先级队列 priority_queue
  7. Android5.x新特性之 Toolbar和Theme的使用
  8. 个人博客满血复活,求测试~~~
  9. php常见的几种排序以及二分法查找
  10. 菜鸟学习Hibernate——简单的一个例子