当前位置: 首页 > news >正文

1114 Family Property (25)

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.

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

题目大意:给定每个人的家庭成员和其自己名下的房产,请统计出每个家庭的人口数、人均房产面积及房产套数。首先在第一行输出家庭个数(所有有亲属关系的人都属于同一个家庭)。随后按下列格式输出每个家庭的信息:家庭成员的最小编号 家庭人口数 人均房产套数 人均房产面积。其中人均值要求保留小数点后3位。家庭信息首先按人均面积降序输出,若有并列,则按成员编号的升序输出。
分析:并查集。这里用哈希表模拟了。将同一个家庭的成员用flag标记成同一个数字,统计有多少不同的flag,相同flag的情况下,有多少人,最小编号,房产总数,房产面积总数并存储,最后输出。

注意0000也是有效的成员编号。

#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define INF 0xffffffff
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
#define db4(x,y,z,r) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<endl
#define db5(x,y,z,r,w) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<", "<<#w<<"="<<(w)<<endl
using namespace std;typedef struct node//家庭成员结构
{int id,flag;//自己的编号,以及对应家庭的编号int fat,mon;//父母的编号int m,area;//自己有多少房产和房产面积
}node;typedef struct family//因为是哈希表存储的成员,最后需要把所有成员拿出来排序
{int id,sum;//该成员的编号,家庭人数总和double sets,area;//这一家庭的平均套数和平均面积
}family;bool cmpnode(node a,node b)//快排比较函数
{return a.flag<b.flag;
}bool cmpans(family a,family b)//快排比较函数
{if(a.area!=b.area)return a.area>b.area;return a.id<b.id;
}int main(void)
{#ifdef testfreopen("in.txt","r",stdin);//freopen("in.txt","w",stdout);clock_t start=clock();#endif //testint n,cnt=1;scanf("%d",&n);node num[10010];//初始化哈希表for(int i=0;i<10000;++i)num[i].id=i,num[i].flag=num[i].fat=num[i].mon=-1,num[i].area=num[i].m=0;for(int i=0;i<n;++i){int a,index=cnt;scanf("%d",&a);scanf("%d%d",&num[a].fat,&num[a].mon);if(num[a].flag!=-1)//如果当前成员已经是某个家庭的成员{//如果父亲或者母亲是某个家庭的成员,需要合并集合,所有被标记的全部改为当前节点标记index=num[a].flag;if(num[a].fat!=-1&&num[a].mon!=-1)//如果父母都在{int temp1=num[num[a].fat].flag,temp2=num[num[a].mon].flag;for(int i=1;i<10000;++i)if((temp1!=-1&&num[i].flag==temp1)||(temp2!=-1&&num[i].flag==temp2))num[i].flag=index;num[num[a].fat].flag=num[num[a].mon].flag=index;}else if(num[a].fat!=-1)//父亲在,母亲不在{int temp1=num[num[a].fat].flag;for(int i=1;i<10000;++i)if(temp1!=-1&&num[i].flag==temp1)num[i].flag=index;}else if(num[a].mon!=-1)//母亲在,父亲不在{int temp2=num[num[a].mon].flag;for(int i=1;i<10000;++i)if(temp2!=-1&&num[i].flag==temp2)num[i].flag=index;}}else if(num[a].fat!=-1&&num[num[a].fat].flag!=-1){//父亲被标记过,同步成父亲的标记index=num[num[a].fat].flag;num[a].flag=index;if(num[a].mon!=-1){int temp2=num[num[a].mon].flag;for(int i=0;i<10000;++i)if(temp2!=-1&&num[i].flag==temp2)num[i].flag=index;num[num[a].mon].flag=index;}}else if(num[a].mon!=-1&&num[num[a].mon].flag!=-1){//母亲被标记过,同步成母亲的标记index=num[num[a].mon].flag;num[a].flag=index;if(num[a].fat!=-1){int temp1=num[num[a].fat].flag;for(int i=0;i<10000;++i)if(temp1!=-1&&num[i].flag==temp1)num[i].flag=index;num[num[a].fat].flag=index;}}else//都没被标记,全部标记成新的标记{index=cnt;num[a].flag=num[num[a].fat].flag=num[num[a].mon].flag=index;cnt++;}int k;scanf("%d",&k);while(k--)//孩子部分同样考虑是否被标记{int aa;scanf("%d",&aa);if(num[aa].flag!=-1){int temp=num[a].flag;index=num[aa].flag;for(int i=0;i<10000;++i)if(num[i].flag==temp)num[i].flag=index;}else num[aa].flag=index;}scanf("%d%d",&num[a].m,&num[a].area);}int total_num=0;node val[10005];for(int i=0;i<10000;++i){if(num[i].flag!=-1)val[total_num++]=num[i];}sort(val,val+total_num,cmpnode);//    for(int i=0;i<total_num;++i)
//        db4(val[i].id,val[i].flag,val[i].m,val[i].area);family ans[total_num+5];int tempflag=val[0].flag,ans_num=0,miniid=val[0].id,cntnum=1,setnum=val[0].m,areanum=val[0].area;for(int i=1;i<total_num;++i){if(val[i].flag==tempflag){miniid=min(val[i].id,miniid);cntnum++;setnum+=val[i].m,areanum+=val[i].area;}else{ans[ans_num].id=miniid;ans[ans_num].sum=cntnum;ans[ans_num].sets=1.0*setnum/cntnum;ans[ans_num].area=1.0*areanum/cntnum;ans_num++;tempflag=val[i].flag,miniid=val[i].id,cntnum=1,setnum=val[i].m,areanum=val[i].area;}}ans[ans_num].id=miniid;ans[ans_num].sum=cntnum;ans[ans_num].sets=1.0*setnum/cntnum;ans[ans_num].area=1.0*areanum/cntnum;ans_num++;printf("%d\n",ans_num);sort(ans,ans+ans_num,cmpans);for(int i=0;i<ans_num;++i){printf("%04d %d %.3f %.3f\n",ans[i].id,ans[i].sum,ans[i].sets,ans[i].area);}#ifdef testclockid_t end=clock();double endtime=(double)(end-start)/CLOCKS_PER_SEC;printf("\n\n\n\n\n");cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位#endif //testreturn 0;
}

相关文章:

1114 Family Property (25)

This time, you are supposed to help us collect the data for family-owned property. Given each persons family members, and the estate&#xff08;房产&#xff09;info under his/her own name, we need to know the size of each family, and the average area and n…...

详细介绍Sd-WebUI提示词的语法规则

AI绘画中最大的门槛就是提示词&#xff0c;对英语水平、文学水平、想象力、灵感等要求较高。不能每次一输入正向提示词&#xff08;positive prompt&#xff09;&#xff0c;就只会写a girl, big eyes, red hair。虽然sd-webui软件可以直接翻译&#xff0c;输入一个子母后会立刻…...

document.body为null问题

调用document.body.append方法出现null的问题&#xff0c;一看就是放在了head中&#xff0c;一种方案是放在最后面&#xff0c;要不就和jquery一样监听&#xff0c;下面是代码 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8…...

2024国赛A问题5

问题五 龙头最大速度优化模型的建立 问题五在问题四的曲线的基础上对速度进行了约束&#xff0c;即在逐步改变龙头速度的情况下&#xff0c;各个龙身的速度也会依次改变&#xff0c;给出龙头的最大行进速度,使得舞龙队各把手的速度均不超过 2 m/s。即可依此构建一个龙头速度的…...

Kalilinux下MySQL的安装

MySQL是一个广泛使用的开源关系型数据库管理系统&#xff0c;它是最流行的关系型数据库之一。在Kalilinux下安装MySQL可以为我们提供方便的数据库管理和开发环境。本文将介绍如何在Kalilinux中安装MySQL&#xff0c;并提供一些常用的代码示例。 步骤一&#xff1a;更新软件包 …...

文件路径与Resource接口详解

目录 第一章、快速了解文件路径1.1&#xff09;什么是文件路径&#xff1f;1.1.1&#xff09;绝对路径1.1.2&#xff09;相对路径 1.2&#xff09;重要&#xff1a;相对路径的表示方法1.2.1) ./ 与 ../ 1.3&#xff09;文件路径与环境变量1.3.1&#xff09;什么是环境变量1.3.2…...

极狐GitLab 17.7正式发布,可从 GitLab 丝滑迁移至极狐GitLab【二】

GitLab 是一个全球知名的一体化 DevOps 平台&#xff0c;很多人都通过私有化部署 GitLab 来进行源代码托管。极狐GitLab 是 GitLab 在中国的发行版&#xff0c;专门为中国程序员服务。可以一键式部署极狐GitLab。 学习极狐GitLab 的相关资料&#xff1a; 极狐GitLab 官网极狐…...

分布式光纤传感|分布式光纤测温|线型光纤感温火灾探测器DTS|DTS|DAS|BOTDA的行业16年的总结【2024年】

背景&#xff1a; 从2008年&#xff0c;从事分布式光纤传感行业已经过了16年时间了&#xff0c;依稀记得2008年&#xff0c;看的第一遍论文就是中国计量大学张在宣老爷子的分布式光纤测温综述&#xff0c;我的经历算是行业内极少数最丰富的之一。混过学术圈&#xff1a; 发表…...

存储过程实现多个分类不同计算规则得到对应的分类、月份和款号

该存储过程 PRO_MON_MDCODE 实现多个分类不同计算规则得到对应的分类、月份和款号,其中线下分类的款最早出现时间会在20230101,最晚是当前月份后12月,电商的款取商品维表的23,24,25年商品年份的A款,其他业务分类逻辑(A-线上,B电商公司,C品牌公司)的款最早出现时间会在2…...

aj-report本地前后端分离部署运行

github项目地址 aj-report-mine 在源代码v1.4版本基础上&#xff0c;本地进行前后端分离部署开发 这里我是进行了整合&#xff0c;把自己在拉取源代码到成功运行过程中的一些东西直接整合&#xff0c;根据下面的步骤即可成功运行 资源获取 夸克网盘(16-github-aj-report-re…...

CSS 过渡动画效果

在 CSS 中&#xff0c;transition 是用来实现元素属性平滑过渡的一个属性。通过 transition&#xff0c;你可以指定当元素的状态发生变化时&#xff0c;如何在一定时间内平滑地过渡到新的样式&#xff0c;而不是立即跳变。 使用于侧边栏展开和收起了&#xff0c;左侧区域的自适…...

网络安全 - DOS

1.1.1 摘要 最近网络安全成了一个焦点&#xff0c;除了国内明文密码的安全事件&#xff0c;还有一件事是影响比较大的——Hash Collision DoS&#xff08;通过Hash碰撞进行的拒绝式服务攻击&#xff09;&#xff0c;有恶意的人会通过这个安全漏洞让你的服务器运行巨慢无比&…...

【强化学习】Stable-Baselines3学习笔记

【强化学习】Stable-Baselines3学习笔记 Stable-Baselines3是什么安装ExampleReinforcement Learning Tips and TricksVecEnv相关在stablebaselines中使用自定义环境 Stable-Baselines3是什么 Stable Baselines3&#xff08;简称SB3&#xff09;是一套基于PyTorch实现的强化学习…...

前端真实面试题自用

一、写在前面 笔者&#xff0c;经过计算机学硕考研的失败后&#xff0c;想谋求一份前端工作实在是太难了。一方面&#xff0c;确实曾经学习过的东西很久没有拾起&#xff0c;另一方面&#xff0c;对于前端面经还是记忆不深刻&#xff0c;特地写此贴记录笔者在真实前端面试中遇…...

vue3和springboot使用websocket通信

前端端口&#xff1a;9090 后端端口&#xff1a;8080 vue3 引入依赖&#xff1a; npm install sockjs-client stomp/stompjs vue页面 <template><div><h1>WebSocket 示例</h1><button click"sendMessage">发送消息</button>…...

JS 解构、数组扩展符和模板字符串的常见用法

文章目录 解构1. 对象解构2. 数组解构 数组扩展符模板字符串 解构 1. 对象解构 想把对象中的属性赋值给变量时, 需要一次一次的赋值&#xff0c;很麻烦。而对象解构, 就是把对象的结构拆解开, 然后把拆解后的属性自动赋值给匹配的变量。 (1) 对象属性赋值变量的传统写法&…...

低代码开源项目Joget的研究——Joget7社区版安装部署

大纲 环境准备安装必要软件配置Java配置JAVA_HOME配置Java软链安装三方库 获取源码配置MySql数据库创建用户创建数据库导入初始数据 配置数据库连接配置sessionFactory编译下载tomcat启动下载aspectjweaver移动jw.war文件编写脚本运行 测试参考资料 Joget&#xff0c;作为一款开…...

Golang 为什么没有注解?

Go 的哲学是:“少就是多,显式优于隐式。”注解虽然方便,但会违背 Go 追求简洁和清晰的设计理念。 什么是注解?为什么看起来很实用? 注解的定义:注解是一种特殊的元信息,用于修饰代码(如类、方法、字段等),让程序或工具在运行时或编译时解析和处理这些信息。例如: …...

Visual Studio Code(VS Code)配置C/C++环境

一、Visual Studio Code安装 Visual Studio Code&#xff0c;下文中简称为VS Code的详细安装方法请参考VSCode安装教程&#xff08;超详细&#xff09;-CSDN博客 二、MinGW编译器下载与配置 1、MinGW介绍 MinGW(Minimalist GNU for Windows)是一款用于Windows 平台的轻…...

LabVIEW软件开发的未来趋势

LabVIEW软件开发的未来趋势可以从以下几个方面来分析&#xff1a; ​ 1. 与AI和机器学习的深度结合 趋势&#xff1a;LabVIEW正在向集成AI和机器学习方向发展&#xff0c;尤其是在数据处理、预测性维护和自动化控制领域。 原因&#xff1a;AI技术的普及使得实验和工业场景中的…...

【WiFi帧结构】

文章目录 帧结构MAC头部管理帧 帧结构 Wi-Fi的帧分为三部分组成&#xff1a;MAC头部frame bodyFCS&#xff0c;其中MAC是固定格式的&#xff0c;frame body是可变长度。 MAC头部有frame control&#xff0c;duration&#xff0c;address1&#xff0c;address2&#xff0c;addre…...

Python:操作 Excel 折叠

💖亲爱的技术爱好者们,热烈欢迎来到 Kant2048 的博客!我是 Thomas Kant,很开心能在CSDN上与你们相遇~💖 本博客的精华专栏: 【自动化测试】 【测试经验】 【人工智能】 【Python】 Python 操作 Excel 系列 读取单元格数据按行写入设置行高和列宽自动调整行高和列宽水平…...

为什么需要建设工程项目管理?工程项目管理有哪些亮点功能?

在建筑行业&#xff0c;项目管理的重要性不言而喻。随着工程规模的扩大、技术复杂度的提升&#xff0c;传统的管理模式已经难以满足现代工程的需求。过去&#xff0c;许多企业依赖手工记录、口头沟通和分散的信息管理&#xff0c;导致效率低下、成本失控、风险频发。例如&#…...

高等数学(下)题型笔记(八)空间解析几何与向量代数

目录 0 前言 1 向量的点乘 1.1 基本公式 1.2 例题 2 向量的叉乘 2.1 基础知识 2.2 例题 3 空间平面方程 3.1 基础知识 3.2 例题 4 空间直线方程 4.1 基础知识 4.2 例题 5 旋转曲面及其方程 5.1 基础知识 5.2 例题 6 空间曲面的法线与切平面 6.1 基础知识 6.2…...

Springcloud:Eureka 高可用集群搭建实战(服务注册与发现的底层原理与避坑指南)

引言&#xff1a;为什么 Eureka 依然是存量系统的核心&#xff1f; 尽管 Nacos 等新注册中心崛起&#xff0c;但金融、电力等保守行业仍有大量系统运行在 Eureka 上。理解其高可用设计与自我保护机制&#xff0c;是保障分布式系统稳定的必修课。本文将手把手带你搭建生产级 Eur…...

Matlab | matlab常用命令总结

常用命令 一、 基础操作与环境二、 矩阵与数组操作(核心)三、 绘图与可视化四、 编程与控制流五、 符号计算 (Symbolic Math Toolbox)六、 文件与数据 I/O七、 常用函数类别重要提示这是一份 MATLAB 常用命令和功能的总结,涵盖了基础操作、矩阵运算、绘图、编程和文件处理等…...

Spring数据访问模块设计

前面我们已经完成了IoC和web模块的设计&#xff0c;聪明的码友立马就知道了&#xff0c;该到数据访问模块了&#xff0c;要不就这俩玩个6啊&#xff0c;查库势在必行&#xff0c;至此&#xff0c;它来了。 一、核心设计理念 1、痛点在哪 应用离不开数据&#xff08;数据库、No…...

企业如何增强终端安全?

在数字化转型加速的今天&#xff0c;企业的业务运行越来越依赖于终端设备。从员工的笔记本电脑、智能手机&#xff0c;到工厂里的物联网设备、智能传感器&#xff0c;这些终端构成了企业与外部世界连接的 “神经末梢”。然而&#xff0c;随着远程办公的常态化和设备接入的爆炸式…...

初探Service服务发现机制

1.Service简介 Service是将运行在一组Pod上的应用程序发布为网络服务的抽象方法。 主要功能&#xff1a;服务发现和负载均衡。 Service类型的包括ClusterIP类型、NodePort类型、LoadBalancer类型、ExternalName类型 2.Endpoints简介 Endpoints是一种Kubernetes资源&#xf…...

scikit-learn机器学习

# 同时添加如下代码, 这样每次环境(kernel)启动的时候只要运行下方代码即可: # Also add the following code, # so that every time the environment (kernel) starts, # just run the following code: import sys sys.path.append(/home/aistudio/external-libraries)机…...