#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 10005;
int num[MAXN],area[MAXN];
vector<int> v[MAXN];
int exist[MAXN];
int vis[MAXN];
int Min ,cnt_f ,cnt_h ,total_a;
struct node{
int Min;
int cnt_f;
double ph;
double pa;
};
bool cmp(struct node a,struct node b){
if(a.pa == b.pa){
return a.Min < b.Min;
}
return a.pa > b.pa;
}
vector<node> ans;
void dfs(int node){
for(int i = 0; i < v[node].size(); i++){
if(!vis[v[node][i]]){
vis[v[node][i]] = 1;
Min = min(Min,v[node][i]);
cnt_f += 1;
cnt_h += num[v[node][i]];
total_a += area[v[node][i]];
dfs(v[node][i]);
}
}
}
int main(void){
int n;
cin >> n;
for(int i = 0; i < n; i++){
int id,cnt,fa,mo;
cin >> id >> fa >> mo >> cnt;
exist[id] = 1;
if(fa != -1){
v[id].push_back(fa);
v[fa].push_back(id);
exist[fa] = 1;
}
if(mo != -1){
v[mo].push_back(id);
v[id].push_back(mo);
exist[mo] = 1;
}
for(int j = 0; j < cnt; j++){
int ch;
cin >> ch;
v[id].push_back(ch);
v[ch].push_back(id);
exist[ch] = 1;
}
cin >> num[id] >> area[id];
}
for(int i = 0; i <= 9999; i++){
if(exist[i] && !vis[i]){
Min = i,cnt_f = 1,cnt_h = num[i],total_a = area[i];
vis[i] = 1;
dfs(i);
struct node temp;
temp.Min = Min;
temp.cnt_f = cnt_f;
temp.pa = total_a * 1.0 / cnt_f;
temp.ph = cnt_h * 1.0 / cnt_f;
ans.push_back(temp);
}
}
sort(ans.begin(),ans.end(),cmp);
cout<<ans.size()<<endl;
for(int i = 0; i < ans.size(); i++){
printf("%04d %d %.3lf %.3lf\n",ans[i].Min,ans[i].cnt_f,ans[i].ph,ans[i].pa);
}
return 0;
}
L2-007. 家庭房产
最新推荐文章于 2022-06-14 17:05:01 发布