当前位置:网站首页>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;
}边栏推荐
- Introduction to message queuing (MQ)
- Basic use of Metasploit penetration testing framework
- The simple problem of leetcode: dismantling bombs
- General undergraduate college life pit avoidance Guide
- Review the configuration of vscode to develop golang
- Notes | numpy-08 Advanced index
- Market status and development prospects of the global autonomous marine glider industry in 2022
- sql语句模糊查询遇到的问题
- [USACO 2009 Dec S]Music Notes
- Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
猜你喜欢

Network security textual research recommendation
![[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

Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis

Source insight garbled code solution

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

Learn to use the idea breakpoint debugging tool

Number of uniform strings of leetcode simple problem

Sdl2 + OpenGL glsl practice (Continued)

Shuttle + alluxio accelerated memory shuffle take-off

On typescript and grammar
随机推荐
Market status and development prospect prediction of global neutral silicone sealant industry in 2022
Day 51 - tree problem
Games101 Lesson 9 shading 3 Notes
[research materials] annual report of China's pension market in 2021 - Download attached
Apache MPM model and ab stress test
Number of uniform strings of leetcode simple problem
Source insight garbled code solution
Shell script -- condition judgment
I stepped on a foundation pit today
Review the configuration of vscode to develop golang
Analysis of proxy usage of ES6 new feature
Notes | numpy-10 Iterative array
Shell script Basics - basic grammar knowledge
Sprintf formatter abnormal exit problem
Handler understands the record
5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
2022 chemical automation control instrument examination summary and chemical automation control instrument certificate examination
MPM model and ab pressure test
Market status and development prospects of the global IOT active infrared sensor industry in 2022
[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)