简单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. 通过httplib2 探索的学习的最佳方式

    在工作中需要对一个视频点播两百次,使其成为热门视频,才能对其p2p情况进行测试.虽然可以手动点播两百次,但是利用python发送200次post请求,能减少很多的工作量.该发送请求的方法用到了http ...

  2. zookeeper的安装及集群配置

    1.解压 2.修改配置文件 cp zoo_sample.cfg zoo.cfg vim zoo.cfg dataDir=/usr/local/zookeeperData 其余采用默认 参数说明: ti ...

  3. 自定义silverlight中datagrid的排序事件

    <sdk:DataGrid AutoGenerateColumns="False" CanUserSortColumns="False" CanUserR ...

  4. php中文乱码问题分析及解决办法

    中文乱码问题产生的原因,主要就是字符编码设置问题:             首先,mysql数据库安装的时候字符编码要选择正确,最好选择utf-8比较保险.如果安装时没有设置正确,找到mysql的安装 ...

  5. android代码格式化方法小结

    转载:http://blog.csdn.net/androidzhaoxiaogang/article/details/7692526 Download the android-formatting. ...

  6. hdu_5762_Teacher Bo(鸽笼原理)

    题目链接:hdu_5762_Teacher Bo 题意: 给你n个点,问你能否找到两对点的曼哈顿距离相等 题解: 最开始看到这题,看数据以为要向nlogn的复杂度发展,结果经验误导了自己,我们仔细观察 ...

  7. servlet第1讲初识

  8. Postgres数据库在Linux中的I/O优化

    I/O 优化1 打开 noatime方法: 修改 /etc/fstab2 调整预读方法: 查看 sudo blockdev --getra /dev/sda 设置 sudo blockdev --se ...

  9. dede 转 帝国

    1.转换栏目 insert into ak_enewsclass (classid,bclassid,classname,myorder,classpath,intro,classpagekey) s ...

  10. 图解HTTP读书笔记--精简版

    这本书重点讲了两点,分别是 HTTP的报文格式 HTTPS比HTTP优秀在哪里 接下来分部分讨论一下: 1. HTTP的报文格式 请求报文格式: 请求行     指明请求方法 请求路径 和协议   如 ...