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行,每行按下 ...
随机推荐
- SpringMVC工程环境由tomcat切换到weblogic,访问不到静态资源
在org.springframework.web.servlet.DispatcherServlet之前加入 <servlet-mapping> <servlet-name>F ...
- 连drawable目录都没搞明白就想开发APP?
我是一个善良的搬运工,关于drawable,来看看这位的博客吧: https://blog.csdn.net/xuaho0907/article/details/72848520 hiahia ...
- Java 从入门到进阶之路(六)
之前的文章我们介绍了 Java 的数组,本章我们来看一下 Java 的对象和类. Java 是一种面向对象语言,那什么是对象呢,对象在编程语言中属于一个很宽泛的概念,我们可以认为万事万物都是对象,每个 ...
- String StringBuffer StringBuilder的异同
1.String与StrIngBuffer StringBuilder的主要区别在于StrIng是不可变对象,每次对String对象进行修改之后,相对于重新创建一个对象. String源码解读: pr ...
- Educational Codeforces Round 72 (Rated for Div. 2)
https://www.cnblogs.com/31415926535x/p/11601964.html 这场只做了前四道,,感觉学到的东西也很多,,最后两道数据结构的题没有补... A. Creat ...
- ReactNative实现GridView
ReactNative内置了ListView组件但是没有类似GridView这样的组件.利用一些已经有的属性是可以实现GridView的,利用ContentContainerStyle的属性然后配合样 ...
- Ubuntu 查看操作系统的位数
查看Ubuntu操作系统的位数是32位还是64位,可以通过以下命令来查看: getconf LONG_BIT 返回32或64 :如图
- springboot启动报错 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
新建了一个springboot项目报一下错误: Failed to configure a DataSource: 'url' attribute is not specified and no em ...
- Mybatis面试题吐血总结
高强度训练第二十天总结:Mybatis面试题 什么是Mybatis? Mybatis 是一个半 ORM(对象关系映射)框架,它内部封装了 JDBC,开发时 只需要关注 SQL 语句本身,不需要花费精力 ...
- Spring Boot(四) Mybatis-MySql
Spring Boot(四) Mybatis-MySql 0.准备数据库表 -- ---------------------------- -- Table structure for person ...