PAT (Advanced Level) 1114. Family Property (25)
简单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)的更多相关文章
- PAT (Advanced Level) 1109. Group Photo (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT (Advanced Level) 1105. Spiral Matrix (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<map> #incl ...
- PAT (Advanced Level) 1101. Quick Sort (25)
树状数组+离散化 #include<cstdio> #include<cstring> #include<cmath> #include<map> #i ...
- PAT (Advanced Level) 1071. Speech Patterns (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1063. Set Similarity (25)
读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #in ...
- PAT (Advanced Level) 1059. Prime Factors (25)
素因子分解. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...
- PAT (Advanced Level) 1051. Pop Sequence (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT (Advanced Level) 1048. Find Coins (25)
先对序列排序,然后枚举较小值,二分较大值. #include<iostream> #include<cstring> #include<cmath> #includ ...
- PAT (Advanced Level) 1028. List Sorting (25)
时间卡的比较死,用string会超时. #include<cstdio> #include<cstring> #include<cmath> #include< ...
随机推荐
- erlang ets表
一.表遍历 通过ets:first/1获取表的第一个关键字,表中下一个关键字用ets:next/2得到,直到ets:next/2返回'$end_of_table' 当多几个进程并发访问ets表时,可以 ...
- Linux RCU机制详解
关于rcu的几点声明: 1:RCU使用在读者多而写者少的情况.RCU和读写锁相似.但RCU的读者占锁没有任何的系统开销.写者与写写者之间必须要保持同步,且写者必须要等它之前的读者全部都退出之后才能释放 ...
- shell编程之sed
一.sed (Stream Editor) 1.定位行:sed -n '12,~3p' pass #从第12行开始,直到下一个3的倍数行(12-15行)sed -n '12,+4p' pass #从第 ...
- Tomcat开发技术之与HTTP服务器的集成
Tomcat最主要的功能是提供Servlet/jsp容器,尽管它也可以作为独立的Java Web服务器,它在对静态资源(如Html文件或图像文件)的处理速度,以及提供的Web服务器治理功能方面都不如其 ...
- 转:CSV Data Set Config 中文乱码问题
从csv读取中文一直乱码. CSV Data Set Config的File encoding为GB2312,对应参数化文件编码也为GB2312,但读取出变量值一直为乱码,后发现是Allow quot ...
- robotframework的分支和循环
分支: run keyword if | condition | do something ... | else if | condition | do something ... ...
- JavaScript高级程序设计:第十三章
第十三章 一.理解事件流 事件流描述的是从页面中接收事件的顺序. 1.事件冒泡 IE的事件流叫做事件冒泡,即事件开始时由最具体的元素接收,然后逐级向上传播到较为不具体的节点.以下面的HTML页面为例: ...
- JavaScript 错误 - Throw、Try 和 Catch
http://www.w3school.com.cn/js/js_errors.asp try 语句测试代码块的错误.catch 语句处理错误.throw 语句创建自定义错误. 错误一定会发生 当 J ...
- A框架 第二部 实例化接收到的get类,调用父类抽象方法,自动执行方法call_user_func_array()
01父类抽象类 abstract.php <?phpabstract class controller_abstract{ protected $app; function __construc ...
- ios小功能
1.开 发过程中,我们通过http请求,后台返回json数据,而有时数据里某一字段的值为null-,然后我们把此值赋值给 NSArray,NSdictionary,或是NSString,然后我们会判断 ...