当前位置:网站首页>1114 family property (25 points)
1114 family property (25 points)
2022-07-03 04:55:00 【vs5】
The main idea of the topic : Given the relationship of each family member , We need to ask for the number of people in each family , Per capita number of real estate units , Area per capita . Output by per capita real estate area in descending order , If equal, press id Output in ascending order (id Is the smallest in every family id)
At first glance, it is a topic of joint search , What needs to be output is the minimum id, So we need to minimize id Build a tree for the root node .
The title is not difficult. , Change the meaning of the question to find the number of connected blocks , And the number of points in each connected block , And update the information of the real estate .
I stepped on the hole , I didn't initialize the number of points in the connected block 0000 This number is included ,debug For a long time ...
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 10000;
typedef pair<int,int> PII;
int p[N],siz[N],st[N],L,id,fa,ma,est,ar,tt,cnt,ch;
vector<PII>area(N);
struct node
{
int id,sum;
double avgnum,avgare;
bool operator < (const node &W)
{
if(W.avgare != avgare) return avgare > W.avgare;
return id < W.id;
}
};
int find(int x)
{
if(p[x] != x) p[x] = find(p[x]);
return p[x];
}
void solve(int a,int b)
{
a = find(a),b = find(b);
if(a != b)
{
if(a < b) swap(a,b);// Give Way id The smallest becomes the parent node
p[a] = b,siz[b] += siz[a];
area[b].first += area[a].first,area[b].second += area[a].second;
}
}
int main()
{
cin >> tt;
vector<PII>e(N);
for(int k = 0; k < tt; k ++)
{
cin >> id >> fa >> ma;
st[id] = true;
if(fa != -1) e[cnt ++] = {id,fa};
if(ma != -1) e[cnt ++] = {id,ma};
cin >> L;
while(L --)
{
cin >> ch;
e[cnt ++] = {id,ch};
}
cin >> est >> ar;
area[id] = {est,ar};
}
for(int i = 0; i < N; i ++) p[i] = i,siz[i] = 1;// initialization
for(int i = 0; i < cnt; i ++)
{
int a = e[i].first,b = e[i].second;
st[b] = true;
solve(a,b);
}
vector<node>v;
for(int i = 0 ; i < N; i ++)
{
if(st[i] && p[i] == i)// Parent node
v.push_back({i,siz[i],(double)area[i].first*1.0/siz[i],(double)area[i].second*1.0/siz[i]});
}
sort(v.begin(),v.end());
cout << v.size() << '\n';
for(auto it : v)
printf("%04d %d %.3lf %.3lf\n",it.id,it.sum,it.avgnum,it.avgare);
return 0;
}
边栏推荐
- RT thread flow notes I startup, schedule, thread
- [clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
- 2022 chemical automation control instrument examination summary and chemical automation control instrument certificate examination
- Career planning of counter attacking College Students
- Shuttle + alluxio accelerated memory shuffle take-off
- Current market situation and development prospect prediction of global direct energy deposition 3D printer industry in 2022
- MPM model and ab pressure test
- Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
- 第十九届浙江省 I. Barbecue
- Market status and development prospect prediction of the global fire extinguisher industry in 2022
猜你喜欢
[PCL self study: filtering] introduction and use of various filters in PCL (continuously updated)
Learning practice: comprehensive application of cycle and branch structure (I)
MC Layer Target
The usage of micro service project swagger aggregation document shows all micro service addresses in the form of swagger grouping
[luatos sensor] 2 air pressure bmp180
移动端——uniapp开发记录(公共请求request封装)
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
【工具跑SQL盲注】
data2vec! New milestone of unified mode
[set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)
随机推荐
Prepare for 2022 and welcome the "golden three silver four". The "summary of Android intermediate and advanced interview questions in 2022" is fresh, so that your big factory interview can go smoothly
7. Integrated learning
Analysis of proxy usage of ES6 new feature
Notes | numpy-10 Iterative array
[SQL injection] joint query (the simplest injection method)
Interface frequency limit access
Pyqt control part (II)
Thesis reading_ Tsinghua Ernie
Shuttle + Alluxio 加速内存Shuffle起飞
Uipath practice (08) - selector
Keepalived热备与HAProxy
《牛客刷verilog》Part II Verilog进阶挑战
Thesis reading_ Chinese NLP_ ELECTRA
The programmer resigned and was sentenced to 10 months for deleting the code. JD came home and said that it took 30000 to restore the database. Netizen: This is really a revenge
[set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)
[set theory] binary relation (example of binary relation operation | example of inverse operation | example of composite operation | example of limiting operation | example of image operation)
Leetcode simple problem delete an element to strictly increment the array
2022 chemical automation control instrument examination summary and chemical automation control instrument certificate examination
[research materials] 2021 China's game industry brand report - Download attached
Market status and development prospects of the global IOT active infrared sensor industry in 2022