当前位置:网站首页>L2-007 family real estate (25 points)
L2-007 family real estate (25 points)
2022-07-06 11:26:00 【%xiao Q】
subject
Give everyone's family members and their own properties , Please count the population of each family 、 Per capita real estate area and number of real estate units .
Input format :
The first line of input gives a positive integer N(≤1000), And then N That's ok , Each line gives a person's property in the following format :
Number Father mother k children 1 … children k Number of real estate units Total area
The number is unique to everyone 4 Number of digits ; The parent and the parent are the number of the parent corresponding to the number ( If you have passed away , Is displayed -1);k(0≤k≤5) It's the number of children of the person ; children i Is the number of their child .
Output format :
First, output the number of families in the first line ( All relatives belong to the same family ). Then output the information of each family in the following format :
Minimum number of family members The number of families Per capita number of real estate units Per capita real estate area
The per capita value shall be kept after the decimal point 3 position . Family information is first output in descending order of per capita area , If there is juxtaposition , Then output... In ascending order of member number .
sample input :
10
6666 5551 5552 1 7777 1 100
1234 5678 9012 1 0002 2 300
8888 -1 -1 0 1 1000
2468 0001 0004 1 2222 1 500
7777 6666 -1 0 2 300
3721 -1 -1 1 2333 2 150
9012 -1 -1 3 1236 1235 1234 1 100
1235 5678 9012 0 1 50
2222 1236 2468 2 6661 6662 1 300
2333 -1 3721 3 6661 6662 6663 1 100
sample output :
3
8888 1 1.000 1000.000
0001 15 0.600 100.000
5551 4 0.750 100.000
analysis
A problem of parallel search set , See code for details !!!
Reference code :
#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <unordered_map>
#define LL long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
#define pre(i, a, b) for(int i = b; i >= a; i--)
using namespace std;
const int N = 1010, M = 1e4;
int n;
bool st[M]; // Mark those id There have been
int p[M];
struct data
{
int id, num, area;
}a[N];
struct stu
{
int id, people;
double num, area;
bool flag;
}ans[M];
// Find the parent node
int find(int x)
{
while(x != p[x]) x = p[x];
return x;
}
// Merge 2 Subtree
void Union(int x, int y)
{
int fx = find(x);
int fy = find(y);
if(fx > fy) p[fx] = fy;
else p[fy] = fx;
}
bool cmp(stu x, stu y)
{
if(x.area != y.area) return x.area > y.area;
return x.id < y.id;
}
int main()
{
cin >> n;
rep(i, 0, M) p[i] = i; // Initialize the parent node of all points for itself
rep(i, 1, n)
{
int id, d_id, m_id, k, son, num, area;
cin >> id >> d_id >> m_id;
st[id] = true;
if(d_id != -1)
{
st[d_id] = true;
Union(id, d_id);
}
if(m_id != -1)
{
st[m_id] = true;
Union(id, m_id);
}
cin >> k;
while(k--)
{
cin >> son;
st[son] = true;
Union(id, son);
}
cin >> num >> area;
a[i] = {
id, num, area};
}
rep(i, 1, n)
{
int id = find(a[i].id);
ans[id].id = id;
ans[id].num += a[i].num;
ans[id].area += a[i].area;
ans[id].flag = true; // Number of marked families
}
int cnt = 0;
// because id The data range is small , Directly enumerate all possible 4 number id, And use the fear and search set to accumulate the family population
rep(i, 0, 9999)
{
if(st[i]) ans[find(i)].people++;
if(ans[i].flag) cnt++;
}
rep(i, 0, 9999)
if(ans[i].flag)
{
ans[i].num = ans[i].num / ans[i].people;
ans[i].area = ans[i].area / ans[i].people;
}
sort(ans, ans + M, cmp);
cout << cnt << endl;
// Because it is output in descending order according to the average area , So you can output directly after sorting
rep(i, 0, cnt - 1)
printf("%04d %d %.3f %.3f\n", ans[i].id, ans[i].people, ans[i].num, ans[i].area);
return 0;
}
边栏推荐
- AI benchmark V5 ranking
- 人脸识别 face_recognition
- [蓝桥杯2021初赛] 砝码称重
- 报错解决 —— io.UnsupportedOperation: can‘t do nonzero end-relative seeks
- MTCNN人脸检测
- Why can't STM32 download the program
- QT creator design user interface
- Remember a company interview question: merge ordered arrays
- vs2019 桌面程序快速入门
- When using lambda to pass parameters in a loop, the parameters are always the same value
猜你喜欢
机器学习笔记-Week02-卷积神经网络
Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
Face recognition_ recognition
AcWing 1298.曹冲养猪 题解
Django运行报错:Error loading MySQLdb module解决方法
Mtcnn face detection
AcWing 1298. Solution to Cao Chong's pig raising problem
Integration test practice (1) theoretical basis
QT creator specify editor settings
[free setup] asp Net online course selection system design and Implementation (source code +lunwen)
随机推荐
Detailed reading of stereo r-cnn paper -- Experiment: detailed explanation and result analysis
L2-004 这是二叉搜索树吗? (25 分)
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
[number theory] divisor
How to configure flymcu (STM32 serial port download software) is shown in super detail
When using lambda to pass parameters in a loop, the parameters are always the same value
02-项目实战之后台员工信息管理
nodejs 详解
PyCharm中无法调用numpy,报错ModuleNotFoundError: No module named ‘numpy‘
Picture coloring project - deoldify
DICOM: Overview
Why can't STM32 download the program
[Thesis Writing] how to write function description of jsp online examination system
01项目需求分析 (点餐系统)
数数字游戏
QT creator specify editor settings
Pytorch基础
人脸识别 face_recognition
QT creator shape
图像识别问题 — pytesseract.TesseractNotFoundError: tesseract is not installed or it‘s not in your path