L2-007. 家庭房产(并查集)
#include <cstdio>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
const int N=1e4+;
const int inf=1e8;
int n;
int f[N];
set<int>st,tt;
set<int>::iterator it;
struct node{
int ns=,S=;
}peo[N];
struct edge{
int Min=inf,num=;
double avgHouse=,avgS=;
bool operator < (const edge x)const &{
if(x.avgS==avgS){
return x.Min>Min;
}
return x.avgS<avgS;
}
}res[N];
vector<edge>sus;
void init(){
for (int i=; i<N; i++) {
f[i]=i;
}
}
int query(int x){
int r=x;
while (f[x]!=x) {
x=f[x];
}
f[r]=x;
return x;
}
void join(int x,int y){
int fx=query(x);
int fy=query(y);
if(fx!=fy){
f[fx]=fy;
}
}
void checkjoin(int x,int d,int m){
st.insert(x);
if(d!=- && m!=-){
st.insert(d);
st.insert(m);
join(d, m);
join(x, d);
}else if(d!=-){
st.insert(d);
join(x, d);
}else if(m!=-){
st.insert(m);
join(x, m);
}
}
int main(){
int x,d,m,k,c;
init();
scanf("%d",&n);
for (int i=; i<n; i++) {
scanf("%d%d%d",&x,&d,&m);
checkjoin(x, d, m);
scanf("%d",&k);
for (int j=; j<k; j++) {
scanf("%d",&c);
st.insert(c);
join(c, x);
}
scanf("%d%d",&peo[x].ns,&peo[x].S);
}
for (it=st.begin(); it!=st.end(); it++) {
x=*it;
int fx=query(x);
if (x==fx) tt.insert(x);
res[fx].Min=min(res[fx].Min, x);
res[fx].num++;
res[fx].avgHouse+=peo[x].ns;
res[fx].avgS+=peo[x].S;
}
for (it=tt.begin(); it!=tt.end(); it++) {
x=*it;
res[x].avgHouse/=res[x].num;
res[x].avgS/=res[x].num;
sus.push_back(res[x]);
}
sort(sus.begin(), sus.end());
printf("%d\n",(int)sus.size());
for (int i=; i<sus.size(); i++) {
printf("%04d %d %.3lf %.3lf\n",sus[i].Min,sus[i].num,sus[i].avgHouse,sus[i].avgS);
}
return ;
}
L2-007. 家庭房产(并查集)的更多相关文章
- PATL2-007. 家庭房产-并查集
L2-007. 家庭房产 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定每个人的家庭成员和其自己名下的房产,请你统计出每个 ...
- TOJ3660家庭关系(并查集+hash+图的连通性)
家庭关系 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte 总提交: 38 测试通过: 9 描述 给定若干家庭成员之间的关系 ...
- L2-007 家庭房产 (25 分) (并查集)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805068539215872 题目: 给定每个人的家庭成员和其自己名 ...
- 天梯赛 L2-007. (并查集) 家庭房产
题目链接 题目描述 给定每个人的家庭成员和其自己名下的房产,请你统计出每个家庭的人口数.人均房产面积及房产套数. 输入格式: 输入第一行给出一个正整数N(<=1000),随后N行,每行按下列格式 ...
- GPLT L2-007 家庭房产 (并查集)
题意: 给定每个人的家庭成员和其自己名下的房产,请你统计出每个家庭的人口数.人均房产面积及房产套数. 思路: 输入和输出各构造一个结构体,利用并查集归并输入,枚举编号进行输出. #include &l ...
- L2-007. 家庭房产(并查集)*
L2-007. 家庭房产 参考博客 #include <iostream> #include <cstdio> #include <cstring> #includ ...
- L2-007 家庭房产 (25分) 并查集
题目链接 题解:并查集把一个家的并在一起,特殊的一点是编号大的并到小的去.这个题有个坑编号可能为0000,会错数据3和5. 1 #include<bits/stdc++.h> 2 usin ...
- 团体程序设计天梯赛-练习集L2-007. 家庭房产
L2-007. 家庭房产 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定每个人的家庭成员和其自己名下的房产,请你统计出每个 ...
- 【PAT-并查集-水题】L2-007-家庭房产
L2-007. 家庭房产 给定每个人的家庭成员和其自己名下的房产,请你统计出每个家庭的人口数.人均房产面积及房产套数. 输入格式: 输入第一行给出一个正整数N(<=1000),随后N行,每行按下 ...
随机推荐
- 个人网站(sysoft.net.cn)被k,公司名都搜索不出来了,怎么办?
今年上班后,好2019年3月初,上班后(年前大病一场 ,两个月没维护网站),发现公司网站所有收录都掉了,搜索公司名都不不到了,宝宝真是惊呆了. 有些人说是百度出了故障,有人说是百度算法. 说句 ...
- python+selenium十:selenium的二次封装
python+selenium十:基于原生selenium的二次封装 from selenium import webdriverfrom selenium.webdriver.support.w ...
- springboot jsp,过滤器,拦截器
springboot使用jsp,过滤器,拦截器(拦截器与过滤器区别重点) jsp使用配置 一 创建springboot项目在maven中暂时只添加两个Dependencies :devtools(热部 ...
- 文章导航-readme
Spring-Boot Spring Boot(一) Hello World Redis 图解Redis之数据结构篇--简单动态字符串SDS 图解Redis之数据结构篇--链表 图解Redis之数据结 ...
- 修改zabbix的端口号
1.前言 zabbix-server的默认端口号是10051.如果存在端口号冲突,需要更改端口号. 以下为更改端口号的步骤. 2.更改配置文件 通常用安装包,也就是yum方式部署的话,其默认的配置文 ...
- 【Python笔记】Python 基础语法
Python 标识符 在 Python 里,标识符由字母.数字.下划线组成. 在 Python 中,所有标识符可以包括英文.数字以及下划线(_),但不能以数字开头. Python 中的标识符是区分大小 ...
- springboot结合mybatis使用pageHelper插件进行分页查询
1.pom相关依赖引入 <dependencies> <dependency> <groupId>org.springframework.boot</grou ...
- mysql5.7初始密码及设置问题
为了加强安全性,MySQL5.7为root用户随机生成了一个密码,如果安装的是RPM包,则默认是在/var/log/mysqld.log中. 可通过# grep "password" ...
- css 精灵图的使用
精灵图的使用 1.给一个容器定义一个大小(宽高) 2.引入背景图 3.定位到自己你想要的图片位置 例如: background-position: 0 0; background-position ...
- kotlin系列文章 --- 1.初识kotlin
简介 Kotlin 是一种在 Java 虚拟机上运行的静态类型编程语言,由Jetbrains设计开发,现在是Android官方开发语言,和Java具有互操作性,可以共存. 为什么选择kotlin? 简 ...