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(房产)info under his/her own name, we need to know the size of each family, and the average area and n…...
详细介绍Sd-WebUI提示词的语法规则
AI绘画中最大的门槛就是提示词,对英语水平、文学水平、想象力、灵感等要求较高。不能每次一输入正向提示词(positive prompt),就只会写a girl, big eyes, red hair。虽然sd-webui软件可以直接翻译,输入一个子母后会立刻…...
document.body为null问题
调用document.body.append方法出现null的问题,一看就是放在了head中,一种方案是放在最后面,要不就和jquery一样监听,下面是代码 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8…...
2024国赛A问题5
问题五 龙头最大速度优化模型的建立 问题五在问题四的曲线的基础上对速度进行了约束,即在逐步改变龙头速度的情况下,各个龙身的速度也会依次改变,给出龙头的最大行进速度,使得舞龙队各把手的速度均不超过 2 m/s。即可依此构建一个龙头速度的…...
Kalilinux下MySQL的安装
MySQL是一个广泛使用的开源关系型数据库管理系统,它是最流行的关系型数据库之一。在Kalilinux下安装MySQL可以为我们提供方便的数据库管理和开发环境。本文将介绍如何在Kalilinux中安装MySQL,并提供一些常用的代码示例。 步骤一:更新软件包 …...
文件路径与Resource接口详解
目录 第一章、快速了解文件路径1.1)什么是文件路径?1.1.1)绝对路径1.1.2)相对路径 1.2)重要:相对路径的表示方法1.2.1) ./ 与 ../ 1.3)文件路径与环境变量1.3.1)什么是环境变量1.3.2…...
极狐GitLab 17.7正式发布,可从 GitLab 丝滑迁移至极狐GitLab【二】
GitLab 是一个全球知名的一体化 DevOps 平台,很多人都通过私有化部署 GitLab 来进行源代码托管。极狐GitLab 是 GitLab 在中国的发行版,专门为中国程序员服务。可以一键式部署极狐GitLab。 学习极狐GitLab 的相关资料: 极狐GitLab 官网极狐…...
分布式光纤传感|分布式光纤测温|线型光纤感温火灾探测器DTS|DTS|DAS|BOTDA的行业16年的总结【2024年】
背景: 从2008年,从事分布式光纤传感行业已经过了16年时间了,依稀记得2008年,看的第一遍论文就是中国计量大学张在宣老爷子的分布式光纤测温综述,我的经历算是行业内极少数最丰富的之一。混过学术圈: 发表…...
存储过程实现多个分类不同计算规则得到对应的分类、月份和款号
该存储过程 PRO_MON_MDCODE 实现多个分类不同计算规则得到对应的分类、月份和款号,其中线下分类的款最早出现时间会在20230101,最晚是当前月份后12月,电商的款取商品维表的23,24,25年商品年份的A款,其他业务分类逻辑(A-线上,B电商公司,C品牌公司)的款最早出现时间会在2…...
aj-report本地前后端分离部署运行
github项目地址 aj-report-mine 在源代码v1.4版本基础上,本地进行前后端分离部署开发 这里我是进行了整合,把自己在拉取源代码到成功运行过程中的一些东西直接整合,根据下面的步骤即可成功运行 资源获取 夸克网盘(16-github-aj-report-re…...
CSS 过渡动画效果
在 CSS 中,transition 是用来实现元素属性平滑过渡的一个属性。通过 transition,你可以指定当元素的状态发生变化时,如何在一定时间内平滑地过渡到新的样式,而不是立即跳变。 使用于侧边栏展开和收起了,左侧区域的自适…...
网络安全 - DOS
1.1.1 摘要 最近网络安全成了一个焦点,除了国内明文密码的安全事件,还有一件事是影响比较大的——Hash Collision DoS(通过Hash碰撞进行的拒绝式服务攻击),有恶意的人会通过这个安全漏洞让你的服务器运行巨慢无比&…...
【强化学习】Stable-Baselines3学习笔记
【强化学习】Stable-Baselines3学习笔记 Stable-Baselines3是什么安装ExampleReinforcement Learning Tips and TricksVecEnv相关在stablebaselines中使用自定义环境 Stable-Baselines3是什么 Stable Baselines3(简称SB3)是一套基于PyTorch实现的强化学习…...
前端真实面试题自用
一、写在前面 笔者,经过计算机学硕考研的失败后,想谋求一份前端工作实在是太难了。一方面,确实曾经学习过的东西很久没有拾起,另一方面,对于前端面经还是记忆不深刻,特地写此贴记录笔者在真实前端面试中遇…...
vue3和springboot使用websocket通信
前端端口:9090 后端端口:8080 vue3 引入依赖: npm install sockjs-client stomp/stompjs vue页面 <template><div><h1>WebSocket 示例</h1><button click"sendMessage">发送消息</button>…...
JS 解构、数组扩展符和模板字符串的常见用法
文章目录 解构1. 对象解构2. 数组解构 数组扩展符模板字符串 解构 1. 对象解构 想把对象中的属性赋值给变量时, 需要一次一次的赋值,很麻烦。而对象解构, 就是把对象的结构拆解开, 然后把拆解后的属性自动赋值给匹配的变量。 (1) 对象属性赋值变量的传统写法&…...
低代码开源项目Joget的研究——Joget7社区版安装部署
大纲 环境准备安装必要软件配置Java配置JAVA_HOME配置Java软链安装三方库 获取源码配置MySql数据库创建用户创建数据库导入初始数据 配置数据库连接配置sessionFactory编译下载tomcat启动下载aspectjweaver移动jw.war文件编写脚本运行 测试参考资料 Joget,作为一款开…...
Golang 为什么没有注解?
Go 的哲学是:“少就是多,显式优于隐式。”注解虽然方便,但会违背 Go 追求简洁和清晰的设计理念。 什么是注解?为什么看起来很实用? 注解的定义:注解是一种特殊的元信息,用于修饰代码(如类、方法、字段等),让程序或工具在运行时或编译时解析和处理这些信息。例如: …...
Visual Studio Code(VS Code)配置C/C++环境
一、Visual Studio Code安装 Visual Studio Code,下文中简称为VS Code的详细安装方法请参考VSCode安装教程(超详细)-CSDN博客 二、MinGW编译器下载与配置 1、MinGW介绍 MinGW(Minimalist GNU for Windows)是一款用于Windows 平台的轻…...
LabVIEW软件开发的未来趋势
LabVIEW软件开发的未来趋势可以从以下几个方面来分析: 1. 与AI和机器学习的深度结合 趋势:LabVIEW正在向集成AI和机器学习方向发展,尤其是在数据处理、预测性维护和自动化控制领域。 原因:AI技术的普及使得实验和工业场景中的…...
23-Oracle 23 ai 区块链表(Blockchain Table)
小伙伴有没有在金融强合规的领域中遇见,必须要保持数据不可变,管理员都无法修改和留痕的要求。比如医疗的电子病历中,影像检查检验结果不可篡改行的,药品追溯过程中数据只可插入无法删除的特性需求;登录日志、修改日志…...
《用户共鸣指数(E)驱动品牌大模型种草:如何抢占大模型搜索结果情感高地》
在注意力分散、内容高度同质化的时代,情感连接已成为品牌破圈的关键通道。我们在服务大量品牌客户的过程中发现,消费者对内容的“有感”程度,正日益成为影响品牌传播效率与转化率的核心变量。在生成式AI驱动的内容生成与推荐环境中࿰…...
镜像里切换为普通用户
如果你登录远程虚拟机默认就是 root 用户,但你不希望用 root 权限运行 ns-3(这是对的,ns3 工具会拒绝 root),你可以按以下方法创建一个 非 root 用户账号 并切换到它运行 ns-3。 一次性解决方案:创建非 roo…...
uniapp中使用aixos 报错
问题: 在uniapp中使用aixos,运行后报如下错误: AxiosError: There is no suitable adapter to dispatch the request since : - adapter xhr is not supported by the environment - adapter http is not available in the build 解决方案&…...
Android第十三次面试总结(四大 组件基础)
Activity生命周期和四大启动模式详解 一、Activity 生命周期 Activity 的生命周期由一系列回调方法组成,用于管理其创建、可见性、焦点和销毁过程。以下是核心方法及其调用时机: onCreate() 调用时机:Activity 首次创建时调用。…...
C++.OpenGL (14/64)多光源(Multiple Lights)
多光源(Multiple Lights) 多光源渲染技术概览 #mermaid-svg-3L5e5gGn76TNh7Lq {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-3L5e5gGn76TNh7Lq .error-icon{fill:#552222;}#mermaid-svg-3L5e5gGn76TNh7Lq .erro…...
代码随想录刷题day30
1、零钱兑换II 给你一个整数数组 coins 表示不同面额的硬币,另给一个整数 amount 表示总金额。 请你计算并返回可以凑成总金额的硬币组合数。如果任何硬币组合都无法凑出总金额,返回 0 。 假设每一种面额的硬币有无限个。 题目数据保证结果符合 32 位带…...
上位机开发过程中的设计模式体会(1):工厂方法模式、单例模式和生成器模式
简介 在我的 QT/C 开发工作中,合理运用设计模式极大地提高了代码的可维护性和可扩展性。本文将分享我在实际项目中应用的三种创造型模式:工厂方法模式、单例模式和生成器模式。 1. 工厂模式 (Factory Pattern) 应用场景 在我的 QT 项目中曾经有一个需…...
高抗扰度汽车光耦合器的特性
晶台光电推出的125℃光耦合器系列产品(包括KL357NU、KL3H7U和KL817U),专为高温环境下的汽车应用设计,具备以下核心优势和技术特点: 一、技术特性分析 高温稳定性 采用先进的LED技术和优化的IC设计,确保在…...
Redis上篇--知识点总结
Redis上篇–解析 本文大部分知识整理自网上,在正文结束后都会附上参考地址。如果想要深入或者详细学习可以通过文末链接跳转学习。 1. 基本介绍 Redis 是一个开源的、高性能的 内存键值数据库,Redis 的键值对中的 key 就是字符串对象,而 val…...
