<p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-stretch: inherit; line-height: 18px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; vertical-align: baseline; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">给定每个人的家庭成员和其自己名下的房产,请你统计出每个家庭的人口数、人均房产面积及房产套数。</p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-stretch: inherit; line-height: 18px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; vertical-align: baseline; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);"><strong>输入格式:</strong></p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-stretch: inherit; line-height: 18px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; vertical-align: baseline; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">输入第一行给出一个正整数N(<=1000),随后N行,每行按下列格式给出一个人的房产:</p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-stretch: inherit; line-height: 18px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; vertical-align: baseline; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);"><strong>编号 父 母 k 孩子<sub style="line-height: 0;">1</sub> ... 孩子<sub style="line-height: 0;">k</sub> 房产套数 总面积</strong></p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-stretch: inherit; line-height: 18px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; vertical-align: baseline; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">其中 <strong>编号</strong> 是每个人独有的一个4位数的编号;<strong>父</strong> 和 <strong>母</strong> 分别是该编号对应的这个人的父母的编号(如果已经过世,则显示<strong>-1</strong>);<strong>k</strong>(0<=k<=5)是该人的子女的个数;<strong>孩子<sub style="line-height: 0;">i</sub></strong>是其子女的编号。</p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-stretch: inherit; line-height: 18px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; vertical-align: baseline; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);"><strong>输出格式:</strong></p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-stretch: inherit; line-height: 18px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; vertical-align: baseline; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">首先在第一行输出家庭个数(所有有亲属关系的人都属于同一个家庭)。随后按下列格式输出每个家庭的信息:</p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-stretch: inherit; line-height: 18px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; vertical-align: baseline; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);"><strong>家庭成员的最小编号 家庭人口数 人均房产套数 人均房产面积</strong></p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-stretch: inherit; line-height: 18px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; vertical-align: baseline; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">其中人均值要求保留小数点后3位。家庭信息首先按人均面积降序输出,若有并列,则按成员编号的升序输出。</p><span style="color: rgb(51, 51, 51); font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; line-height: 18px; background-color: rgb(250, 250, 250);">输入样例:</span><pre style="margin-top: 1.5em; margin-bottom: 1.5em; padding: 0px; border: 0px; font-stretch: normal; line-height: 18px; font-family: 'Droid Sans Mono', Consolas, 'Courier New', monospace; vertical-align: baseline; overflow: auto; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">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
输出样例:
3
8888 1 1.000 1000.000
0001 15 0.600 100.000
5551 4 0.750 100.000
<pre name="code" class="cpp">#include<map>
#include<queue>
#include<cmath>
#include<cstdio>
#include<stack>
#include<iostream>
#include<cstring>
#include<algorithm>
#define LL int
#define inf 0x3f3f3f3f
#define eps 1e-8
#include<vector>
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define LL __int64
using namespace std;
struct node{
int id,fid,mid,ch;
int num[6],dor;
double s;
}q[1010];
struct N{
int id,cnt;
double tao,sq;
}ans[10010],res[10010];
int f[10010];
bool vis[10010],bj[10010];
int fi(int x){
return x == f[x]?x:f[x] = fi(f[x]);
}
bool op(N a,N b){
if(a.sq==b.sq)
return a.id < b.id;
return a.sq > b.sq;
}
void mer(int a,int b){
int x = fi(a);
int y = fi(b);
x > y?f[x] = y:f[y] = x;
}
int main(){
int n,m,j,i,k;
while(~scanf("%d",&n)){
for(i = 0;i <= 10000;++ i){
f[i] = i;
bj[i] = vis[i] = false;
ans[i].cnt = ans[i].tao = ans[i].sq = 0;
}
int sum = 0;
//memset(ans,0,sizeof(ans));
for(i = 0 ;i < n;++ i){
scanf("%d%d%d%d",&q[i].id,&q[i].fid,&q[i].mid,&q[i].ch);
vis[q[i].id ] = true;
if(q[i].fid != -1){
vis[q[i].fid ] = true;
mer(q[i].id,q[i].fid);
}
if(q[i].mid != -1){
vis[q[i].mid ] = true;
mer(q[i].id,q[i].mid);
}
for(j = 0;j < q[i].ch;j++){
scanf("%d",&q[i].num[j]);
if(q[i].num[j] != -1){
vis[q[i].num[j] ] = true;
mer(q[i].id,q[i].num[j]);
}
}
scanf("%d%lf",&q[i].dor,&q[i].s);
}
for(i = 0;i < n;++ i){
int now = fi(q[i].id);
ans[now].id = now;
ans[now].tao += q[i].dor;
ans[now].sq += q[i].s;
vis[now] = true;
}
for(i = 0;i<10000;++ i){
if(vis[i]){
int tmp = fi(i);
ans[tmp].cnt++;
}
}
for( i = 0; i < 10000; ++i){
if(vis[i]){
int tmp = fi(i);
if(!bj[tmp]){
bj[tmp] = true;
res[sum].tao = ans[tmp].tao/(double)ans[tmp].cnt;
res[sum].sq = ans[tmp].sq/(double)ans[tmp].cnt;
res[sum].id = ans[tmp].id;
res[sum++].cnt = ans[tmp].cnt;
}
}
}
sort(res,res+sum,op);
printf("%d\n",sum);
for(i = 0; i < sum; i++) {
if(res[i].id < 10)
printf("000%d %d %.3lf %.3lf\n", res[i].id, res[i].cnt, res[i].tao, res[i].sq);
else if(res[i].id < 100)
printf("00%d %d %.3lf %.3lf\n", res[i].id, res[i].cnt, res[i].tao, res[i].sq);
else if(res[i].id < 1000)
printf("0%d %d %.3lf %.3lf\n", res[i].id, res[i].cnt, res[i].tao, res[i].sq);
else
printf("%d %d %.3lf %.3lf\n", res[i].id, res[i].cnt, res[i].tao, res[i].sq);
}
}
return 0;
}