PAT甲级1114

MATLAB使用贝叶斯网络bnt工具箱:使用手册详解 MATLAB使用贝叶斯bnt网络工具箱:使用手册详解 阅读详情

PAT甲级1114

题目大意:给出n组数据,每行给出当前人员的id,父母亲的id,孩子数量,孩子id,以及房产和总资产。求出一共有多少个家庭,然后每行要输出每个家庭最小成员的id,总人数,平均房产以及平均总资产;按照平均总资产降序排列,如果有相同的则按照最小成员升序排列。
DFS查找连通图问题,也可以用并查集。设置孩子双亲数组保存每个人员的孩子和父母,注意这里要去重,每次输入数据的时候要双向保存。定义hash数组存放已经出现过得人员(应对单人家庭的情况)。

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <math.h>
#include <algorithm>
#define MAXN 10010
using namespace std;

struct family{
	int minmember,membernum;
	double avgsets,avgarea;
};
int sets[MAXN],area[MAXN];
vector<int> child[MAXN],parents[MAXN];
vector<family> fm;
int n;
bool visit[MAXN]={false},hashTable[MAXN];
void insert(vector<int> &a,int x){
	for(int i=0;i<a.size();i++){
		if(a[i]==x) return ;
	}
	a.push_back(x);
}
bool cmp(family a,family b){
	if(a.avgarea!=b.avgarea) return a.avgarea>b.avgarea;
	else return a.minmember<b.minmember;
}
void DFS(int index,int &minnumber,int &totalnum,int &totalsets,int &totalarea){
	visit[index]=true;
	totalarea+=area[index];
	totalsets+=sets[index];
	if(minnumber>index) minnumber=index;
	for(int i=0;i<parents[index].size();i++){
		if(!visit[parents[index][i]]){
			totalnum++;
			DFS(parents[index][i],minnumber,totalnum,totalsets,totalarea);
		}
	}
	for(int i=0;i<child[index].size();i++){
		if(!visit[child[index][i]]){
			totalnum++;
			DFS(child[index][i],minnumber,totalnum,totalsets,totalarea);
		}
	}
}
int main(){
	int id,fatherid,matherid,childid,childnum;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&id);
		scanf("%d%d",&fatherid,&matherid);
		hashTable[id]=true;
		if(fatherid!=-1){
			hashTable[fatherid]=true;
			insert(parents[id],fatherid);
			insert(child[fatherid],id);
		}
		if(matherid!=-1){
			hashTable[matherid]=true;
			insert(parents[id],matherid);
			insert(child[matherid],id);
		}
		scanf("%d",&childnum);
		for(int i=0;i<childnum;i++){
			scanf("%d",&childid);
			insert(child[id],childid);
			insert(parents[childid],id);
		}
		scanf("%d%d",&sets[id],&area[id]);
	}
	for(int i=0;i<MAXN;i++){
		if(!visit[i]&&hashTable[i]){
			int totalnum=1,totalarea=0,totalsets=0,minnumber=MAXN;
			DFS(i,minnumber,totalnum,totalsets,totalarea);
			family tmp;
			tmp.minmember=minnumber,tmp.membernum=totalnum,tmp.avgsets=totalsets*1.0/totalnum,tmp.avgarea=totalarea*1.0/totalnum;
			fm.push_back(tmp);
		}
	}
	sort(fm.begin(),fm.end(),cmp);
	printf("%d\n",fm.size());
	for(int i=0;i<fm.size();i++){
		printf("%04d %d %.3f %.3f\n",fm[i].minmember,fm[i].membernum,fm[i].avgsets,fm[i].avgarea);
	}
	system("pause");
	return 0;
}
2025年06月中国电子学会青少年软件编程(图形化)等级考试试卷(三级)答案 + 解析 阅读详情

相关推荐

STM32HAL库学习笔记九——LCD显示

本文不会对驱动编写做特别详细的描述,以记录CubeMX的部署流程为主。

weixin_44762233的博客 6918

pat甲级1114

1114Family 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 n...

weixin_30911451的博客 193

vue 获取el-table多选的选中行

<el-table :data='tableData' ref="multipleTable" v-loading='loading' border max-height='700' style='width: 100%' size="mini"> <el-table-column type="selection" width="55"></el-table-column> <el-table-column label

且听风吟的博客 6649

PAT【甲级】1114

题目链接:PAT【甲级】1114 题目简述:给定每个⼈人的家庭成员和其⾃自⼰己名下的房产,要求统计出每个家庭的⼈人⼝口数、⼈人均房产⾯积及房产套数。家庭信息⾸先按⼈均⾯积降序输出,若有并列,则按成员编号的升序输出。 #include<bits/stdc++.h> using namespace std; unordered_map<int, int> areas, sets, members; int father[10000], exist[10000], minID[10000

qq_41375322的博客 230

IOPaint模型部署教程

IOPaint是一款功能全面且强大的AI图像处理工具,它不仅免费开源,还由SOTA(State-of-the-Art,即最先进)AI模型驱动,为图像编辑和修复带来了前所未有的便利和高效。以下是对IOPaint的详细介绍:

SJJS_1的博客 1541

SWIFT报文实战指南:从MT700到MT799的信用证操作全解析

本文深入解析了国际贸易中信用证操作的核心SWIFT报文流程,从开证的MT700到各类通知、修改及结算报文(如MT707、MT730、MT754、MT732/734等)。通过实战案例与关键字段拆解,指导外贸与银行从业者精准处理报文,规避风险,并探讨了利用自动化工具提升处理效率的方法,助力保障跨境交易顺畅。

weixin_29015801的博客 878

PAT甲级题解A1114 Family Property (25分)

PAT甲级题解 A1114 Family Property (25分) #include<iostream> #include<vector> #include<map> #include<algorithm> #include<cmath> using namespace std; const int eps = 1e-7;//double类型比较,这题貌似不用。 const int MAXN = 10010; int fa[MAXN], set

cold_lemon的博客 237

Python爬虫实战:使用Scrapy+Playwright高效爬取全球专利数据库

本文将详细介绍如何使用Python最新技术栈(Scrapy+Playwright)构建一个高效的专利数据库爬虫系统。我们将从爬虫基础知识讲起,逐步深入到反爬应对策略、分布式爬虫架构以及数据存储方案,最终实现一个完整的专利数据采集系统。专利数据是技术创新领域的重要信息资源,包含技术描述、权利要求、申请人信息等宝贵数据。中国国家知识产权局(CNIPA)美国专利商标局(USPTO)欧洲专利局(EPO)世界知识产权组织(WIPO)

2201_76125261的博客 1382

PAT 甲级 1114(Family Property)

PAT 甲级 1042题目要求翻译代码思路 题目要求 翻译 给定每个人的家庭成员和其自己名下的房产,请你统计出每个家庭的人口数、人均房产面积及房产套数。首先在第一行输出家庭个数(所有有亲属关系的人都属于同一个家庭)。随后按下列格式输出每个家庭的信息:家庭成员的最小编号 家庭人口数 人均房产套数 人均房产面积。其中人均值要求保留小数点后3位。家庭信息首先按人均面积降序输出,若有并列,则按成员编号的升序输出。 代码 #include<iostream> #include<algorithm&

qq_42865772的博客 364

嵌入式Zephyr RTOS面试题及参考答案

在Zephyr中,为自定义外设编写Devicetree绑定(Bindings)有助于内核理解设备树中自定义外设节点的含义和属性。首先,需要创建一个.yaml格式的绑定文件,通常存放在目录下对应的子目录中,文件名应能反映外设的类型和功能。绑定文件的开头要定义基本信息,包括字段,用于简要描述外设的功能和用途;compatible字段,它是一个字符串列表,用于匹配设备树中自定义外设节点的compatible属性,设备树节点和绑定文件通过这个字段关联起来。接下来,要定义外设节点的属性。使用properties。

大模型大数据攻城狮的专栏 986

RK3568平台(USB篇)USB基础知识

现象:把USB设备比如Android手机接到PC答1:是USB控制器,是USB控制器内嵌的root hub.答2. windows里已经有了USB的总线驱动程序,接入USB设备后,是"总线驱动程序"知道你是"android phone"提示你安装的是"设备驱动程序"。USB总线驱动程序负责:识别USB设备, 给USB设备找到对应的驱动程序。答3. PC的USB口内部,D-和D+接有15K的下拉电阻,未接USB设备时为低电平USB设备的USB口内部,D-或D+接有1.5K的上拉电阻;

weixin_49303682的博客 1658

*PAT_甲级_1114 Family Property (25分) (C++)【并查集】

目录 1,题目描述 2,思路 数据结构 算法 3,AC代码 4,解题过程 1,题目描述 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 37...

&再见萤火虫&的博客 287

2025华为OD机试真题+全流程解析+备考攻略+面试技巧+机考经验分享+Java/python/JS/C++/C语言实现

本专栏包含华为 OD 机试最新的 A卷+B卷+C卷+D卷+E卷题库,为全网最全、最新题库,500+真题。每一篇文章都包含了题目描述、解题思路以及实现代码。同时免费提供最新的在线OJ 刷题系统。已有上百名小伙伴通过刷真题题库通过了华为od机考,拒绝一切形式的代考,替考行为!!!以下是本专栏详细内容介绍:本专栏提供在线OJ刷题系统:OJ题库OJ系统注册&使用教程:OJ使用教程其他专栏以及答疑介绍:50+ 高频面试手撕真题,已有上百位小伙伴高频认证。1:机试没过,半年的冷冻期。2:已经订阅过我专栏的同学,推荐新人

MISAYAONE的博客 2225

【PAT甲级 - C++题解】1114 Family Property

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 695

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

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

刷题

阿正的梦工坊 755

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

PAT 甲级 1114  Family Property

1114 Family Property (25 point(s)) 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...

漫浸天空的雨色的备忘录~ 721

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

PAT 甲级 1114

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

rv0p111 496

PAT 甲级 1114 PAT Ranking 个人错误总结

并查集有点乱讲道理。 我写这篇博客顺便屡一下思路。 1遇到并查集要把数据和father分开,无脑写一个find和合并。 2如果是记录所有节点的统计信息,由于没法通过父亲找孩子,所以直接用一个bool表记录所有见过的节点。 3可以写成路径压缩形式,注意用find函数内压缩得到的最终不见得压缩了。 比如a-b-c,d-e-f. 这时候d和a合并,d成为a的father,这里a和孩子并没有更新(没有办法更新,因为没有从父亲到孩子的反向路径)。需要在最后bool遍历的时候每个人find一下。 4对于bool取同根数

☁的博客 189

PAT 甲级 1114 Family Property

题意:此题给定一些人,然后给出一些人的相关信息,求出总的家族有多少个,以及每个家族的最小id以及家族的人数,平均财产,平均面积; 思路:此处要输出家族中id最小的那个,在我们归并的时候,要把id大的子树并到id小的根上面去,这样就能保证树根是最小的id了,这里也是一个比较有技巧性的一个点,再有就是计算人的个数的时候要定义一个访问数组,用于计算家族中的人数用的 代码: #include&lt...

qq_42152681的博客 161

PAT甲级1114 并查集

分数 25。

qq_62368250的博客 255

1114 Family Property-PAT甲级

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

amf12345的博客 179

PAT 甲级 1112 1113 1114 1115 解题报告

昨天鸽了一天 导致今天还没补完前面的四道题 明天大概会补上(吧 整体难度:简单(这套卷肯定是12月的) 时间:2小时10分钟(第四个题非逼自己用不熟悉动态树,其实本来四个题都属于简单类型的,这个时间用的过多) PAT 1112 找出卡顿键 题目大意:现在键盘有若干卡顿键,如果遇到卡顿则会重复输出n次,给出一段字符串,找出卡顿键。 思路:遍历字符串,找出每个字符连续出现的所有次数(这里数据量不大,放肆地所以用map<char,vector < int > >都完全足够) 注意细

Modberge的博客 293

PAT甲级——1114 Family Property (并查集)

1114Family 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 ne...

小熊猫的博客 330

PAT甲级-1114 Family Property

并查集 C++

weixin_74092648的博客 587

PAT甲级——A1114 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 e...

weixin_30632089的博客 149

*浙大PAT甲级 1114 并查集

考察并查集,并附加记录额外信息。 为了得到一个家族中的最小id,我们可以将最小的id做为这个家族的根。并将整个家族的信息如家族人数,家族房产数,家族的房产面积。 然后通过排序,输出相应结果。 AC代码: #include #include #include #include #include #include #include #include #include #include #inc

威的博客 1098
上一篇: PAT甲级1110
下一篇: PAT甲级1122
zerohawk
博客等级 码龄8年 3粉丝 78原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值