当前位置:网站首页>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;
}
边栏推荐
- Truncated sentences of leetcode simple questions
- Leetcode simple question: the key with the longest key duration
- SSM framework integration
- 关于开学的准备与专业认知
- 雇佣收银员(差分约束)
- The 19th Zhejiang I. barbecue
- [luatos sensor] 1 light sensing bh1750
- Market status and development prospect prediction of global fermentation acid industry in 2022
- Pyqt control part (II)
- Market status and development prospects of the global IOT active infrared sensor industry in 2022
猜你喜欢
ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)
Career planning of counter attacking College Students
5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
Handler understands the record
Compile and decompile GCC common instructions
Do you know UVs in modeling?
Basic use of Metasploit penetration testing framework
Thesis reading_ Tsinghua Ernie
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
随机推荐
Market status and development prospect prediction of global fermented plant protein industry in 2022
C language self-made Games: Sanzi (tic tac toe chess) intelligent chess supplement
论文阅读_中文NLP_ELECTRA
Market status and development prospect prediction of the global fire hose industry in 2022
Thesis reading_ ICD code_ MSMN
2022 registration examination for safety production management personnel of hazardous chemical production units and examination skills for safety production management personnel of hazardous chemical
【SQL注入点】注入点出现位置、判断
2022-02-11 daily clock in: problem fine brush
The usage of micro service project swagger aggregation document shows all micro service addresses in the form of swagger grouping
Handler understands the record
Market status and development prospect forecast of global button dropper industry in 2022
Thesis reading_ Chinese NLP_ ELECTRA
[PCL self study: filtering] introduction and use of various filters in PCL (continuously updated)
Uipath practice (08) - selector
[BMZCTF-pwn] 18-RCTF-2017-Recho
The reason why the entity class in the database is changed into hump naming
The simple problem of leetcode: dismantling bombs
Notes | numpy-07 Slice and index
Symbol of array element product of leetcode simple problem
UiPath实战(08) - 选取器(Selector)