当前位置:网站首页>L2-007 family real estate (25 points) and search set or graph traversal
L2-007 family real estate (25 points) and search set or graph traversal
2022-04-23 00:36:00 【hys__ handsome】
Topic details - L2-007 Family property (25 branch ) (pintia.cn)
Union checking set
Ideas : Record the number of families 、 The idea of real estate quantity and real estate area is the same as that of connecting blocks ( Remember to initialize ), When a new node is merged into the set, the attribute value of the node is added to the ancestor node ( Set the minimum number to ancestor ), One last poll to get ancestors (f[x] = x spot ) The number of is the number of families . Then the structure is sorted and output .
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 10010;
//cnt The number of properties , pn Number of families
int f[N],cnt[N],area[N],pn[N];
vector<int> child(N);
struct Node{
int id,pn;
double avlc,avla; // Number of houses per capita Area per capita
bool operator<(const Node &t) const{
if(avla != t.avla) return avla > t.avla;
return id < t.id;
}
};
int getf(int x){
if(x == f[x]) return x;
else return f[x] = getf(f[x]);
}
void merge(int a,int b){
int ta = getf(a);
int tb = getf(b);
if(ta != tb){
if(ta > tb) swap(ta,tb);
f[tb] = ta;
cnt[ta] += cnt[tb];
area[ta] += area[tb];
pn[ta] += pn[tb];
}
}
void init(int x){
pn[x] = 1;
f[x] = x;
}
int main(){
int n;
cin>>n;
memset(f,-1,sizeof f);
memset(cnt,0,sizeof cnt);
memset(area,0,sizeof area);
for(int i = 0; i < n; i++){
int num,father,mother,k;
cin>>num>>father>>mother>>k;
for(int j = 0; j < k; j++){
cin>>child[j];
if(f[child[j]] == -1) init(child[j]);
}
int fc,zarea;
cin>>fc>>zarea;
if(f[num] == -1) init(num);
cnt[getf(num)] += fc;
area[getf(num)] += zarea;
if(father != -1) {
if(f[father] == -1) init(father);
merge(num,father);
}
if(mother != -1) {
if(f[mother] == -1) init(mother);
merge(num,mother);
}
for(int j = 0; j < k; j++) merge(num,child[j]);
}
vector<Node> ans;
for(int i = 0; i < N; i++)
if(f[i] == i)
ans.push_back({i,pn[i],1.0*cnt[i]/pn[i],1.0*area[i]/pn[i]});
sort(ans.begin(),ans.end());
cout<<ans.size()<<'\n';
for(int i = 0; i < ans.size(); i++)
printf("%04d %d %.3lf %.3lf\n",ans[i].id,ans[i].pn,ans[i].avlc,ans[i].avla);
return 0;
}
Graph traversal
L2-007 Family property (25 branch )_ One more line and go to sleep -CSDN Blog
This may be better written .
版权声明
本文为[hys__ handsome]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230033479412.html
边栏推荐
- ArcGIS urban living area land suitability evaluation (III)
- 随笔8:错误解决Error in readPNG(paste(location,“/“,pattern.type[i],“.png“,sep = ““)):unable to open C:/
- [essay contest] the first essay contest of tidb community column. Come and gather all the surrounding areas at one time!
- 【AI视野·今日Sound 声学论文速览 第四期】Thu, 21 Apr 2022
- Alternative scheme of 24V ~ 48V magnetic absorption track lamp fs2459 to mp2459
- repeat_ dijkstra
- 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目
- C console application flash when running solution
- (turn to) C # best tool set: IDE, analysis, automation tools, etc
- TiDB 在连锁快餐企业丨海量交易与实时分析的应用探索
猜你喜欢

湖泊的水色、水环境、水文遥感的区别

ArcGIS 城市生活区用地适宜性评价(四)

ArcGIS urban living area land suitability evaluation (III)

ArcGIS urban living area land suitability evaluation (IV)

Linear basis (various templates + examples)

网线IP配置

C#/.Net 使用QuestPDF操作生成PDF更快更高效!

命令行修改电脑IP

MP2459被完美替代内部集成有功率MOSFET管FS2459的60V0.5A降压IC

Intelligent wireless transmission module, cv5200 helps UAV mesh networking, wireless communication transmission scheme
随机推荐
Generation and mutual conversion of ArcGIS tin ground surface and grid ground surface
Calculation of Beifu scaling factor
[essay contest] the first essay contest of tidb community column. Come and gather all the surrounding areas at one time!
湖泊的水色、水环境、水文遥感的区别
Symbolization of ArcGIS surface tin surface data
MySQL built-in function
According to this effective method, UI automation testing is so simple
2.58 - write the program is little endian, which returns 1 when compiled and run on the small end method machine and 0 when compiled and run on the large end method machine. This program should be abl
ArcGIS 制作3D遥感影像图
ArcGIS 城市生活区用地适宜性评价(三)
[image classification] reproduce senet with the simplest code. Beginners must not miss (pytorch)
牛客NC13251模
L2-035 完全二叉树的层序遍历 (25 分)
Progrès de la recherche sur la télédétection des paramètres phénologiques de la végétation
Acwing spring daily question - do you know ABC
[play with lighthouse] build a temporary mailbox system that can be collected and destroyed immediately
BUUCTF 穿越时空的思念
智能无线传输模组,CV5200助力无人机mesh组网,无线通信传输方案
MySQL -- data type
C# 11 的这个新特性,我愿称之最强!