简单DFS。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std; struct X
{
int id;
int Father,Mother;
int k;
int son[];
int M_estate;
int Area;
}s[+];
int n;
int f[+];
struct Ans
{
int id;
int M;
int sum_set;
int sum_area;
}ans[+];
int sz;
int indx[+]; vector<int>g[+];
int min_id;
int sum;
int sum_set;
int sum_area; bool cmp(const Ans&a,const Ans&b)
{
if(1.0*a.sum_area/a.M==1.0*b.sum_area/b.M) return a.id<b.id;
return 1.0*a.sum_area/a.M>1.0*b.sum_area/b.M;
} void dfs(int x)
{
ans[sz].id=min_id;
ans[sz].M=sum;
ans[sz].sum_area=sum_area;
ans[sz].sum_set=sum_set; for(int i=;i<g[x].size();i++)
{
if(f[g[x][i]]==) continue;
f[g[x][i]]=; min_id=min(min_id,g[x][i]);
sum=sum+;
sum_set=sum_set+s[g[x][i]].M_estate;
sum_area=sum_area+s[g[x][i]].Area; dfs(g[x][i]);
}
} int main()
{
for(int i=;i<=;i++)
{
s[i].Father=-;
s[i].Mother=-;
s[i].k=;
s[i].Area=;
s[i].M_estate=;
} scanf("%d",&n);
for(int i=;i<=n;i++)
{
int ID; scanf("%d",&ID); indx[i]=ID;
s[ID].id=ID;
scanf("%d%d",&s[ID].Father,&s[ID].Mother);
scanf("%d",&s[ID].k);
for(int j=;j<s[ID].k;j++) scanf("%d",&s[ID].son[j]);
scanf("%d",&s[ID].M_estate);
scanf("%d",&s[ID].Area); if(s[ID].Father!=-){
g[s[ID].id].push_back(s[ID].Father);
g[s[ID].Father].push_back(s[ID].id);
}
if(s[ID].Mother!=-){
g[s[ID].id].push_back(s[ID].Mother);
g[s[ID].Mother].push_back(s[ID].id);
}
for(int j=;j<s[ID].k;j++)
{
g[s[ID].id].push_back(s[ID].son[j]);
g[s[ID].son[j]].push_back(s[ID].id);
}
} memset(f,,sizeof f); sz=;
for(int i=;i<=n;i++)
{
if(f[s[indx[i]].id]==) continue;
min_id=s[indx[i]].id;
sum=;
sum_set=s[indx[i]].M_estate;
sum_area=s[indx[i]].Area;
f[s[indx[i]].id]=;
dfs(s[indx[i]].id);
sz++;
} sort(ans,ans+sz,cmp);
printf("%d\n",sz);
for(int i=;i<sz;i++)
{
printf("%04d %d %.3lf %.3lf\n",ans[i].id,ans[i].M,1.0*ans[i].sum_set/ans[i].M,1.0*ans[i].sum_area/ans[i].M);
} return ;
}

PAT (Advanced Level) 1114. Family Property (25)的更多相关文章

  1. PAT (Advanced Level) 1109. Group Photo (25)

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  2. PAT (Advanced Level) 1105. Spiral Matrix (25)

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<map> #incl ...

  3. PAT (Advanced Level) 1101. Quick Sort (25)

    树状数组+离散化 #include<cstdio> #include<cstring> #include<cmath> #include<map> #i ...

  4. PAT (Advanced Level) 1071. Speech Patterns (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  5. PAT (Advanced Level) 1063. Set Similarity (25)

    读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #in ...

  6. PAT (Advanced Level) 1059. Prime Factors (25)

    素因子分解. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...

  7. PAT (Advanced Level) 1051. Pop Sequence (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  8. PAT (Advanced Level) 1048. Find Coins (25)

    先对序列排序,然后枚举较小值,二分较大值. #include<iostream> #include<cstring> #include<cmath> #includ ...

  9. PAT (Advanced Level) 1028. List Sorting (25)

    时间卡的比较死,用string会超时. #include<cstdio> #include<cstring> #include<cmath> #include< ...

随机推荐

  1. Brackets + Sass 学习心得

    大家知道Brackets是一个可以实时浏览html页面修改效果的工具,对于前段开发人员应该不会陌生,有了它,布局页面再也不是什么困难了, 目前为止已经更新到1.6了. 下载最新版可以到官方网: htt ...

  2. mongoDB1--什么是mongoDB

    mongodb1.mongodb与其它nosql数据库的区别我们之前应该接触过redis或者memcached,他们属于key-value数据库,他们运用哈希算法关联起来,能够达到快速的查询目的.而m ...

  3. jail brak 获取当前安装app列表

    ios 5 6 7 可以通过解析"/private/var/mobile/Library/Caches/com.app.mobile.installation.plist" 文件获 ...

  4. 框架基础:ajax设计方案(一)---集成核心请求

    报告,我要说话!xp被历史淘汰了,IE6 say goodbye了,太TM开心了,从此不要兼容IE6了,哈哈哈哈哈哈 报告,我要说话!IE这sb为啥不早点被杀掉呢,找工作听说要兼容IE,立马软了,唉唉 ...

  5. 《C++ Primer》之面向对象编程(四)

    纯虚函数 在前面所提到过的 Disc_item 类提出了一个有趣的问题:该类从 Item_base 继承了 net_price 函数但没有重定义该函数.因为对 Disc_item 类而言没有可以给予该 ...

  6. VBS调用windows api函数(postmessage)实现后台发送按键脚本

    '=========================================================================='' VBScript Source File - ...

  7. Java良葛格 学习笔记

    学习一个新的事物时,如果遇到一些概念无法很快理解,这可能是因为要理解概念会需要其它概念先建立起来,所以先暂时放下这个疑问也是一个学习方法,称之为“存疑” ,在以后的学习过程中待必要的概念学会后,目前的 ...

  8. JSP基本语法--实例演练

    基本语法概括:<%@page>,<%@include>,<jsp:include>,<jsp:forward> 加上数据库操作,可以开发动态web了. ...

  9. MySQL数据备份和恢复

    1.数据备份 mysqldump -uroot -p databasename > file.sql 2.数据还原 mysql -u root -p databasename < file ...

  10. docker install for centos7

    CentOS Docker runs on CentOS 7.X. An installation on other binary compatible EL7 distributions such ...