当前位置:网站首页>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;
}边栏推荐
- Leetcode simple question: the key with the longest key duration
- 2022-02-11 daily clock in: problem fine brush
- 2022 registration examination for safety production management personnel of hazardous chemical production units and examination skills for safety production management personnel of hazardous chemical
- [luatos sensor] 1 light sensing bh1750
- Learning practice: comprehensive application of cycle and branch structure (I)
- C language self-made Games: Sanzi (tic tac toe chess) intelligent chess supplement
- [tools run SQL blind note]
- stm32逆向入门
- Leetcode simple question: check whether two string arrays are equal
- Silent authorization login and registration of wechat applet
猜你喜欢

JDBC database operation
![[research materials] 2022q1 game preferred casual game distribution circular - Download attached](/img/13/5a67c5d08131745759fdc70a71cf0f.jpg)
[research materials] 2022q1 game preferred casual game distribution circular - Download attached
![[research materials] annual report of China's pension market in 2021 - Download attached](/img/24/622aeeb38de16ac84128b362ceeddb.jpg)
[research materials] annual report of China's pension market in 2021 - Download attached

【工具跑SQL盲注】

LVS load balancing cluster of efficient multi-purpose cluster (NAT mode)

String matching: find a substring in a string

7. Integrated learning

Small sample target detection network with attention RPN and multi relationship detector (provide source code, data and download)

The simple problem of leetcode: dismantling bombs
![[luatos sensor] 2 air pressure bmp180](/img/88/2a6caa5fec95e54e3fb09c74ba8ae6.jpg)
[luatos sensor] 2 air pressure bmp180
随机推荐
String matching: find a substring in a string
《牛客刷verilog》Part II Verilog进阶挑战
Thesis reading_ Chinese medical model_ eHealth
[SQL injection] joint query (the simplest injection method)
2022-02-12 daily clock in: problem fine brush
The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
7. Integrated learning
Current market situation and development prospect forecast of the global fire boots industry in 2022
stm32逆向入门
Literature reading_ Research on the usefulness identification of tourism online comments based on semantic fusion of multimodal data (Chinese Literature)
Handling record of electric skateboard detained by traffic police
Shell script Basics - basic grammar knowledge
Number of 1 in binary (simple difficulty)
[research materials] 2021 China's game industry brand report - Download attached
Notes | numpy-09 Broadcast
Career planning of counter attacking College Students
[luatos sensor] 2 air pressure bmp180
5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
Interface frequency limit access
Notes | numpy-08 Advanced index