PAT a1114

PAT A1114 Family Property (25分) GPLT L2-007 家庭房产 (25分) PAT A1114 Family Property (25分) GPLT L2-007 家庭房产 (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 un... 阅读详情

目的:统计家庭个数,输出每个家庭人数和人均住宅,人均居住面积。

输入:

N  单个小家庭的个数

小家庭信息格式

名字 父母 孩子个数  孩子1 孩子2....住宅数  居住面积

输出:

大家庭个数

大家庭中id最小的人  人数  平均居住房子个数 平均居住面积

算法:

并查集可以用来统计大家庭个数,而且把id最小的作为父亲结点容易找到每个家庭的代表。

小家庭中每个人用vis[]来记录,若是出现了就是true,若没有就是false。

以set存每个小家庭在大家庭的代表,用来统计大家庭的个数。

以每个大家庭的代表为名建立三个unordered_map,分别统计每个大家庭的人数,住宅数目,住宅面积。

再将这三项和代表名字同意为一个结点,建立链表。再对链表排序。输出。

#include<stdio.h>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<set>

using namespace std;

const int maxn = 1010;
struct node{
    int g;
    int a;
};
struct answer{
    int id;
    int m;
    double avg;
    double ava;
};

int father[10010];
unordered_map<int,node> info;
unordered_map<int,int>  member,estate,area;
unordered_map<int,bool>  vis;
vector<answer> ans;
int N,M,A;
int findfather(int x)
{
    int F;
    if(x==father[x]) return x;
    else
    {
        F = findfather(father[x]);
        father[x] = F;
        return F;
    }
}
void Union(int a,int b)
{
    int fa = findfather(a);
    int fb = findfather(b);
    if(fa<fb)
    {
        father[fb] = fa;
    }else
    {
        father[fa] = fb;
    }
}
bool cmp(answer a,answer b)
{
    if(a.ava!=b.ava)
    {
        return a.ava>b.ava;
    }else
    {
        return a.id<b.id;
    }
}
int main()
{
    for(int i=0;i<10010;i++)
    {
        father[i] = i;
    }
    scanf("%d",&N);

    int u,v;
    for(int i=0;i<N;i++)
    {
        scanf("%d",&u);
        vis[u] = true;
        for(int j=0;j<2;j++)
        {
            scanf("%d",&v);
            if(v!=-1)
            {
                vis[v] = true;
                Union(u,v);
            }
        }
        int k;
        scanf("%d",&k);
        for(int j=0;j<k;j++)
        {
            scanf("%d",&v);
            vis[v] = true;
            Union(u,v);
        }
        scanf("%d%d",&M,&A);
        info[u] = node{M,A};
    }
    set<int> family;
    for(unordered_map<int,bool>::iterator it = vis.begin();it!=vis.end();it++)
    {
        family.insert(findfather(it->first));
        member[findfather(it->first)]++;
    }
    for(unordered_map<int,node>::iterator it = info.begin();it!=info.end();it++)
    {

        estate[findfather(it->first)] += it->second.g;
        area[findfather(it->first)] += it->second.a;
    }
    printf("%d\n",family.size());
    for(set<int>::iterator it=family.begin();it!=family.end();it++)
    {
        int m;
        double g,a;
        m = member[*it];
        g = (1.0*estate[*it])/m;
        a = (1.0*area[*it])/m;
        ans.push_back(answer{*it,m,g,a});
    }
    sort(ans.begin(),ans.end(),cmp);
    for(int i=0;i<ans.size();i++)
    {
        printf("%04d %d %.3f %.3f\n",ans[i].id,ans[i].m,ans[i].avg,ans[i].ava);
    }
    return 0;

}

 

本地部署gradle 在部署CAS构建执行包时,如果按照CAS的官方命令gradlew clean build,如果系统没安装过gradle,这个步骤将会从网上下载gradle,但是进度非常慢,耗时很长。为了更快地完成项目构建,我们可以直接在本地部署好gradle,节省一点时间。 阅读详情

相关推荐

在trae CN中使用conda环境(已解决)

Trae CN 是字节跳动于 2025 年 3 月 3 日发布的国内首个 AI 原生集成开发环境(AI IDE)123。

zwzscnds的博客 6937

PAT A1114

难度不大,就是过于繁琐 #include<iostream> #include<set> #include<vector> #include<algorithm> using namespace std; const int maxn = 10000; int n, father[maxn]; struct node{ double mest, area; }Node[maxn]; struct family{ int id, m; double .

学习笔记,不喜勿喷! 134

【深度学习】手把手教你在远程服务器上跑 YOLOv3 相关代码(含环境配置)

这篇文章主要记录了如何配置项目环境以及如何在远程服务器上跑 YOLOv3 模型。

作者正在煮茶中... 2384

pat a 1114

#include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include <unordered_set> using namespace std; const int maxv=10010; int father[maxv]; bool v...

blxl313的博客 170

uni踩坑笔记 - 离线打包调起微信分享后从微信返回APP时黑屏

apk能成功调起微信并进行分享操作,但分享完成后点击回到应用后应用出现黑屏的情况,并在约3-5秒后自动重启。

weixin_46737742的博客 5215

ESP32-S3打造离线语音助手:从零部署自定义唤醒词与本地大模型推理【实战指南】

本文详细介绍了如何利用ESP32-S3芯片打造离线语音助手,包括自定义唤醒词训练与本地大模型推理的实战指南。通过硬件架构解析、音频处理优化及性能调优技巧,实现低延迟、高隐私保护的语音交互方案,特别适合智能家居和物联网应用。

weixin_30296405的博客 608

pat A1114

网上找了一篇博客,链接给出https://blog.youkuaiyun.com/jolivan/article/details/59481949 但它存在一个问题:拥有共同孩子的两个人没有归到同一个家庭 自己动手修改后: //pat A1114 Family Property(25 分) #include &lt;cstdio&gt; #include &lt;algorithm&gt; #incl...

qq_38705851的博客 418

YOLO26涨点改进 | 全网首发Conv独家改进篇 | CVPR 2025 | 引入GCConv卷积改进YOLO26,含GCC3k2二次创新,能够捕捉更加丰富和复杂的特征信息,助力高效涨点

本文提出了一种基于GCConv模块的YOLO26目标检测模型改进方案。GCConv模块通过多路径结构增强特征学习能力,在训练阶段采用垂直多卷积和水平多路径配置,推理时重参数化为单一3x3卷积,显著提升推理速度而不损失性能。实验表明,该模块在复杂场景和多尺度目标检测任务中表现优异,特别适合资源受限的实时应用场景。文章详细介绍了GCConv的网络结构、核心代码实现、YAML配置文件修改方法,并提供了两种改进方案(GCConv和GCC3k2)的具体配置指导。

Ai缝合怪、助力小伙伴高效发论文 321

PAT——1114 全素日

以上图片来自新浪微博,展示了一个非常酷的“全素日”:2019年5月23日。即不仅20190523本身是个素数,它的任何以末尾数字3结尾的子串都是素数。本题就请你写个程序判断一个给定日期是否是“全素日”。

Jamaple的博客 760

HQChart实战教程49-点击修改K线颜色及背景色

HQChart实战教程49-点击修改K线颜色及背景色需求效果图步骤1. 注册点击监听事件2. 修改K颜色添加一个自定义颜色的K线klineoption清空所有自定义颜色的K线option交流QQ群: 950092318HQChart代码地址完整例子 需求 对点击的K线修改颜色。 效果图 步骤 1. 注册点击监听事件 事件ID JSCHART_EVENT_ID.ON_CLICK_CHART_PAINT, 注册监听事件见教程 HQChart使用教程5- K线图控件操作函数说明 this.Create=func

小银 2911

让 PyCharm 代码“发光”:高亮插件与特效全攻略

PyCharm 作为一款强大的 Python IDE,支持多种插件让代码“发光”——无论是动态输入特效、彩虹括号,还是霓虹主题,都能让你的代码脱颖而出!进入 File → Settings → Editor → Color Scheme → Rainbow Brackets。进入 File → Settings → Appearance & Behavior → Material Theme。进入 File → Settings → Editor → Color Scheme → General。

qq_43580271的博客 3837

第十三天PAT-A1114 Family Property并查集详细注解

A1114 Descripiton: 家族产权,给出N个人的家族关系即其所拥有的房产数和总面积,求这一系列人属于几个家族,并求其家族人均房产数和人均面积。 思路: 由于输入当前人的时候,其孩子的房产数和面积还没输入,所以第一遍输入没法计算房产总数和面积总数,于是我在第一遍输入的时候直接不做集合求并了,而是将所有与当前人为一家人(包括父母节点)的下标存储在结构体vector<int>child中,当所有人的房产数和总面积都输入完毕后,再从头到尾遍历每个人、取出要合并为一家人的下标进行合并; id

giggle66的博客 243

100个Python实战项目(七)实现摩斯密码翻译器

作者主页:海拥 作者简介:优快云全栈领域优质创作者、HDZ核心组成员、蝉联C站周榜前十 粉丝福利:往期获奖记录 每周送6~9本书,不定期送各种小礼品(搪瓷杯、抱枕、鼠标垫、马克杯等) 摩斯密码是一种将文本信息作为一系列通断的音调、灯光或咔嗒声传输的方法,无需特殊设备,熟记的小伙伴即可直接翻译。它以电报发明者Samuel F. B. Morse的名字命名。 算法 算法非常简单。英语中的每个字符都被一系列“点”和“破折号”代替,或者有时只是单数的“点”或“

努力是为了站在万人之中,成为别人的光 1万+

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

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

PAT_A1114#Family Property

Source: PAT A1114Family Property(25分) Description: This time, you are supposed to help us collect the data for family-owned property. Given each person's family members, and the estate(房产)...

weixin_34146986的博客 205

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

【PAT】A1114 Family Property【并查集】

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

elegant coder 731

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

PAT A1114. Family Property

1114. Family Property (25) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This time, you are supposed to help us col

u014226072的专栏 273

【并查集】PAT A1114 Family Property

文章目录题目描述知识点实现码前思考代码实现码后反思 题目描述 知识点 并(Union)查(Find)集(Set)(刚好就是并查集的三个核心思想) 实现 码前思考 看到这种“家族”,发现它是类似于集合的概念的,那么肯定要想到使用并查集。 并查集使用就两个函数 findFather 和 Union ,其中 findFather 要注意 路径压缩 即可! 我的思想是每次读入一行数据就更新一个家族...

yc_cy1999的博客 220

PAT A1114 Family Property

PAT A1114 Family Property 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...

qq_42347617的博客 178

1114. Family Property (25)[并查集]

1. 原题: https://www.patest.cn/contests/pat-a-practise/1114 2. 思路: 题意: 找出同一个有关系的家庭里的人数,房产套数及总面积。 思路: 并查集或者dfs算法。 集合问题,并查集优先。 我是先把结点进行合并, 合并好后按照根结点值升序(因为s[i].parent是负值,绝对值是该集合的人数),同时累计该集合的套数及

坚不萌 343

PAT A1114题目记录。以及出错的地方

我在初始化的地方错了,后面找了好久才找出来。呜呜呜 #include <iostream> #include <algorithm> #include <cstdio> #include <stdio.h> #include <math.h> #include <queue> using namespace std; int ...

weixin_44980441的博客 638

1114. Family Property (25)(PAT 并查集)

题目地址https://www.patest.cn/contests/pat-a-practise/1114ac注意 主要是并查集,不能漏掉 int fa[N];int find(int x) { if(x == fa[x]) return x; return fa[x] = find(fa[x]); }void merg(int x, int y) { int xx = fin

master-dragon的专栏 971

PAT | A1114 Family Property

并查集 #include <iostream> #include <unordered_map> #include <vector> #include <algorithm> using namespace std; struct Family{ int numOfMembers; int numOfHouses; int totalAre...

yehonglin29的博客 222

pat 1114. Family Property (25)

https://www.patest.cn/contests/pat-a-practise/1114#include #include #include #include #include #include #include #include #include using namespace std; typedef struct family { int minId; in

guojiaqi007的专栏 344

[PAT] A1114 Family Property

并查集 题目大意 给出每个人名下的房产和家庭关系,求出每个家庭的总人数即人均房产数和房产面积。第一行输出家庭个数(所有有亲属关系的人都属于同一个家庭)。随后按下列格式输出每个家庭的信息:家庭成员的最小编号 家庭人口数 人均房产套数 人均房产面积。其中人均值要求保留小数点后3位。家庭信息首先按人均面积降序输出;若有并列,则按成员编号的升序输出。 思路 用并查集。分别用两个结构体存储,一个用...

yue的博客 189
上一篇: PAT a1115
下一篇: PAT a1113
CSlerner
博客等级 码龄9年 153粉丝 55原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值