当前位置: 首页 > 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技术的普及使得实验和工业场景中的…...

Leetcode 3577. Count the Number of Computer Unlocking Permutations

Leetcode 3577. Count the Number of Computer Unlocking Permutations 1. 解题思路2. 代码实现 题目链接&#xff1a;3577. Count the Number of Computer Unlocking Permutations 1. 解题思路 这一题其实就是一个脑筋急转弯&#xff0c;要想要能够将所有的电脑解锁&#x…...

CMake控制VS2022项目文件分组

我们可以通过 CMake 控制源文件的组织结构,使它们在 VS 解决方案资源管理器中以“组”(Filter)的形式进行分类展示。 🎯 目标 通过 CMake 脚本将 .cpp、.h 等源文件分组显示在 Visual Studio 2022 的解决方案资源管理器中。 ✅ 支持的方法汇总(共4种) 方法描述是否推荐…...

Spring是如何解决Bean的循环依赖:三级缓存机制

1、什么是 Bean 的循环依赖 在 Spring框架中,Bean 的循环依赖是指多个 Bean 之间‌互相持有对方引用‌,形成闭环依赖关系的现象。 多个 Bean 的依赖关系构成环形链路,例如: 双向依赖:Bean A 依赖 Bean B,同时 Bean B 也依赖 Bean A(A↔B)。链条循环: Bean A → Bean…...

VM虚拟机网络配置(ubuntu24桥接模式):配置静态IP

编辑-虚拟网络编辑器-更改设置 选择桥接模式&#xff0c;然后找到相应的网卡&#xff08;可以查看自己本机的网络连接&#xff09; windows连接的网络点击查看属性 编辑虚拟机设置更改网络配置&#xff0c;选择刚才配置的桥接模式 静态ip设置&#xff1a; 我用的ubuntu24桌…...

jmeter聚合报告中参数详解

sample、average、min、max、90%line、95%line,99%line、Error错误率、吞吐量Thoughput、KB/sec每秒传输的数据量 sample&#xff08;样本数&#xff09; 表示测试中发送的请求数量&#xff0c;即测试执行了多少次请求。 单位&#xff0c;以个或者次数表示。 示例&#xff1a;…...

云安全与网络安全:核心区别与协同作用解析

在数字化转型的浪潮中&#xff0c;云安全与网络安全作为信息安全的两大支柱&#xff0c;常被混淆但本质不同。本文将从概念、责任分工、技术手段、威胁类型等维度深入解析两者的差异&#xff0c;并探讨它们的协同作用。 一、核心区别 定义与范围 网络安全&#xff1a;聚焦于保…...

Appium下载安装配置保姆教程(图文详解)

目录 一、Appium软件介绍 1.特点 2.工作原理 3.应用场景 二、环境准备 安装 Node.js 安装 Appium 安装 JDK 安装 Android SDK 安装Python及依赖包 三、安装教程 1.Node.js安装 1.1.下载Node 1.2.安装程序 1.3.配置npm仓储和缓存 1.4. 配置环境 1.5.测试Node.j…...

react更新页面数据,操作页面,双向数据绑定

// 路由不是组件的直接跳转use client&#xff0c;useEffect&#xff0c;useRouter&#xff0c;需3个结合&#xff0c; use client表示客户端 use client; import { Button,Card, Space,Tag,Table,message,Input } from antd; import { useEffect,useState } from react; impor…...

使用VMware克隆功能快速搭建集群

自己搭建的虚拟机&#xff0c;后续不管是学习java还是大数据&#xff0c;都需要集群&#xff0c;java需要分布式的微服务&#xff0c;大数据Hadoop的计算集群&#xff0c;如果从头开始搭建虚拟机会比较费时费力&#xff0c;这里分享一下如何使用克隆功能快速搭建一个集群 先把…...

Ubuntu 安装 Mysql 数据库

首先更新apt-get工具&#xff0c;执行命令如下&#xff1a; apt-get upgrade安装Mysql&#xff0c;执行如下命令&#xff1a; apt-get install mysql-server 开启Mysql 服务&#xff0c;执行命令如下&#xff1a; service mysql start并确认是否成功开启mysql,执行命令如下&am…...