日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

C++学习之路 | PTA(甲级)—— 1114 Family Property (25分)(带注释)(并查集)(精简)

發布時間:2024/7/23 c/c++ 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++学习之路 | PTA(甲级)—— 1114 Family Property (25分)(带注释)(并查集)(精简) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1114 Family Property (25分)
This time, you are supposed to help us collect the data for family-owned property. Given each person’s family members, and the estate(房產)info under his/her own name, we need to know the size of each family, and the average area and number of sets of their real estate.
Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤1000). Then N lines follow, each gives the infomation of a person who owns estate in the format:
ID Father Mother k Child
?1
?? ?Child
?k
?? M
?estate
?? Area
where ID is a unique 4-digit identification number for each person; Father and Mother are the ID’s of this person’s parents (if a parent has passed away, -1 will be given instead); k (0≤k≤5) is the number of children of this person; Child
?i
?? 's are the ID’s of his/her children; M
?estate
?? is the total number of sets of the real estate under his/her name; and Area is the total area of his/her estate.
Output Specification:

For each case, first print in a line the number of families (all the people that are related directly or indirectly are considered in the same family). Then output the family info in the format:
ID M AVG
?sets
?? AVG
?area
??
where ID is the smallest ID in the family; M is the total number of family members; AVG
?sets
?? is the average number of sets of their real estate; and AVG
?area
?? is the average area. The average numbers must be accurate up to 3 decimal places. The families must be given in descending order of their average areas, and in ascending order of the ID’s if there is a tie.
Sample Input:

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
Sample Output:

3
8888 1 1.000 1000.000
0001 15 0.600 100.000
5551 4 0.750 100.000

#include<iostream> #include<set> #include<vector> #include<map> #include<algorithm> using namespace std; const int maxn = 10000; int pre[maxn]; struct node {//存儲開始輸入的人的基本信息int id, house;double area; }; struct family {//輸出的家庭結構體int id, number;double house, area; }; bool cmp(family a, family b)//自定義比較函數 {if (a.area != b.area)return a.area > b.area;else return a.id < b.id; } int find(int x)//并查集模板,查找 {while (x != pre[x]) x = pre[x];return x; } void merge(int x, int y)//并查集模板,合并 {int a = find(x);int b = find(y);if (a != b) pre[a] = b; } int main() {int n, x;cin >> n;set<int>s;//存儲每人的編號,默認升序map<int, node>nodes;//記錄人的房產信息for (int i = 0; i < maxn; i++)pre[i] = i;//初始化pre數組for (int i = 0; i < n; i++){int id, p1, p2, k, house, id1;//分別記錄編號 父 母 k 孩子1 ... 孩子k 房產套數double area;// 總面積cin >> id >> p1 >> p2 >> k;s.insert(id);//插入idif (p1 != -1)//有爸爸{s.insert(p1);merge(id, p1);}if (p2 != -1)//有媽媽{s.insert(p2);merge(id, p2);}for (int j = 0; j < k; j++)//隨后的家庭成員{cin >> id1;s.insert(id1);merge(id1, id);}cin >> house >> area;nodes[id] = node{ id,house,area };//記錄該人的家庭信息}set<int>s1;//記錄家庭編號(也可以理解記錄著每個家庭的老大)map<int, vector<int>>m;//記錄家庭編號()和成員編號for (auto it = s.begin(); it != s.end(); it++){int fa = find(*it);m[fa].push_back(*it);s1.insert(fa);}cout << s1.size() << endl;//輸出家庭的個數vector<family>v1;for (auto it = s1.begin(); it != s1.end(); it++){int fa = *it;double house = 0, area = 0;for (auto tmp = 0; tmp < m[fa].size(); tmp++)//將每個家庭的成員及其房產計算匯總,放入family結構體中{house += nodes[m[fa][tmp]].house;area += nodes[m[fa][tmp]].area;}v1.push_back(family{ m[fa][0],int(m[fa].size()),house * 1.0 / (int)m[fa].size(),area * 1.0 / (int)m[fa].size() });}sort(v1.begin(), v1.end(), cmp);//進行排序for (int i = 0; i < v1.size(); i++) {printf("%04d %d %.3lf %.3lf", v1[i].id, v1[i].number, v1[i].house, v1[i].area);if (i < v1.size() - 1) puts("");} }

總結

以上是生活随笔為你收集整理的C++学习之路 | PTA(甲级)—— 1114 Family Property (25分)(带注释)(并查集)(精简)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 99热偷拍 | 波多野结衣av片 | 男人的天堂网在线 | 琪琪伦伦影院理论片 | 男人操女人免费视频 | 国产精品美女av | 成人国产在线视频 | 中文字幕7 | 久久精品www人人爽人人 | 黑人一区二区三区四区五区 | 免费观看在线观看 | 日韩精品一二 | 国产一区二区三区视频免费观看 | 韩国黄色视屏 | 黄色aaaa| 国产精品久久777777换脸 | 香蕉视频在线播放 | 亚洲午夜视频 | 五月深爱 | 伊人网站| 天堂色网 | 国产剧情久久久 | 中文字幕在线观看亚洲 | 色www情 | 欧美日韩黄色网 | 欧美日韩久久精品 | 俄罗斯精品一区二区三区 | 亚洲性网 | 欧美成人a交片免费看 | 中国毛片网 | 色婷婷综合五月 | 91极品身材尤物theporn | 亚洲一区中文字幕在线观看 | 国产一二三四在线 | aaaaaa毛片| 99re在线观看| 91免费影片| 国产精品第五页 | 一级黄色a | 亚洲成人精品网 | 91精品国产高清一区二区三蜜臀 | 日韩一区二区三区中文字幕 | 日本视频二区 | 午夜精品福利在线观看 | 国产欧美一区二区在线观看 | 自拍偷拍电影 | 三上悠亚ed2k | 狠狠艹狠狠干 | 国产精品一区二区黑人巨大 | 在线观看无码精品 | 94av| 亚洲成人精品一区二区三区 | 亚洲色欲色欲www在线观看 | 亚洲国产麻豆 | 亚洲av乱码久久精品蜜桃 | 欧美一区二区三区激情啪啪 | 久久免费影院 | 欧美777| 午夜亚洲aⅴ无码高潮片苍井空 | 影音先锋中文字幕在线播放 | 久久h视频| 一区二区三区四区高清视频 | 人妻av一区二区三区 | 精品人妻一区二区三区三区四区 | 日本三级一区二区三区 | 成人小视频免费在线观看 | 天天插天天 | 国产污污视频 | 日韩国产区 | 私库av在线 | 黑人操日本女优 | 欧美精品一区二区三 | 五月婷婷深爱 | 91九色国产ts另类人妖 | 亚洲男人第一网站 | 欧美 丝袜 自拍 制服 另类 | 日本伊人色 | 顶级尤物极品女神福利视频 | 草草在线影院 | 国产精品老牛影院99av | 天天爽天天干 | 国产精品福利影院 | 色夜av| 青青草国内自拍 | 免费在线观看av | 国产精品久久久久久在线观看 | 高清三区 | 91pao| a在线免费 | www在线观看视频 | 在线黄色免费网站 | 在线观看免费视频 | 国产精品456 | 精品视频网| 成人免费在线观看网站 | 十八禁一区二区三区 | 波多野结衣乳巨码无在线观看 | 99热偷拍| 一区二区三区四区亚洲 |