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< ...
随机推荐
- ios 字符串的操作汇总
//将NSData转化为NSString NSString* str = [[NSString alloc] initWithData:response encoding:NSUTF8S ...
- 28.按要求编写一个Java应用程序: (1)定义一个类,描述一个矩形,包含有长、宽两种属性,和计算面积方法。 (2)编写一个类,继承自矩形类,同时该类描述长方体,具有长、宽、高属性, 和计算体积的方法。 (3)编写一个测试类,对以上两个类进行测试,创建一个长方体,定义其长、 宽、高,输出其底面积和体积。
//矩形父类 package d922A; public class Rect { private double l,w; Rect(double c,double k) { l=c; w=k; } ...
- 利用socket模块检查端口存活并邮件警报
可以用来监控一些端口. import socket def check_server(addr, port): s = socket.socket() try: s.connect((addr, po ...
- js中call方法的使用介绍
js call call 方法 请参阅 应用于:Function 对象 要求 版本 5.5 调用一个对象的一个方法,以另一个对象替换当前对象. call([thisObj[,arg1[, arg2[, ...
- selenium C#下的zencart自动化测试(WFloginUrlPayment)环境4.0
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- zencart 后台目录产品黄色icon_yellow_on.gif 解决方案
解决方法,导入时候发现 更新成功! - 型号: as NO.1209 就是重复model 文件位置:manager\includes\modules\category_product_listing. ...
- hud 2099
#include <stdio.h> #include <stdlib.h> int main() { int m,n,i,flag; ) { flag=; && ...
- first os
Make your first OS. (MikeOS). check out here
- jquery checkbox 操作
1.jquery 获取所有选中和未选中的checkbox 未选中 var unCheckedBoxs = $("input[name='myCheckbox']").not(&qu ...
- CentOS 7 BIND 主从搭建
主机 10.2.0.15 从机 10.2.0.14 1 主机配置$vim /etc/named.bodani.com.zones zone"bodani.com" IN { typ ...