日韩性视频-久久久蜜桃-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分)(带注释)(并查集)(精简)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 少妇久久久久久久 | 秋霞国产| 亚洲制服丝袜一区 | 久久久久亚洲av成人无码电影 | 九九热免费在线视频 | 亚洲色图第一页 | 国产日韩精品一区 | 亚洲调教欧美在线 | 日本三级中文字幕在线观看 | 亚洲伊人久久综合 | 久久久涩 | 日本一区二区三区精品视频 | 亚洲www视频| 中文字母av | 不卡的av片| 乖女从小调教h尿便器小说 欧美韩一区二区 | 国产精品久久影视 | 欧美一级电影在线 | 天天插天天狠天天透 | 性生生活性生交a级 | 99re这里只有精品在线 | 7色av | 九九精品视频在线观看 | 黄色录象片 | 日本50路肥熟bbw | 久久久久久国产精品无码 | 伊人久久一区二区 | 亚洲av首页在线 | 好吊妞这里只有精品 | 亚洲激情另类 | 黄色片网战 | 密桃成熟时在线观看 | 在线观看视频免费 | 国产探花视频在线观看 | 毛片久久久 | 新天堂在线 | 激情福利在线 | 日日艹 | 日韩一级片中文字幕 | 在线涩涩 | 少女忠诚电影高清免费 | 中文字幕色片 | 黑白配高清国语在线观看 | 亚洲性视频网站 | 女厕厕露p撒尿八个少妇 | 成年人视频网站 | 91精品国产成人观看 | 日韩精美视频 | 日韩在线视频观看 | av免费国产 | 国产精品视频a | 天天天天天天天干 | 青青草成人免费视频 | 老司机在线永久免费观看 | 反差在线观看免费版全集完整版 | 亚洲精品成人a | 亚洲欧美日韩图片 | 久久午夜夜伦鲁鲁片无码免费 | 西西4444www大胆无视频 | 夜夜操天天 | 欧美成人aaaaⅴ片在线看 | 日本大乳美女 | 成人免费视频观看视频 | 国产激情久久久 | 激情四射婷婷 | 色老头一区 | www.男人的天堂 | 中国黄色一级片 | 亚洲人在线观看 | 日本色综合网 | 伊人情人综合 | 中文字幕无码日韩专区免费 | 无码人妻精品一区二区三区夜夜嗨 | 国产在线小视频 | 一区二区三区在线免费视频 | 午夜精品免费观看 | 三区在线 | 国产成人+综合亚洲+天堂 | 天堂亚洲网 | 男女啪动最猛动态图 | 免费成人在线电影 | 日本在线视频不卡 | 亚洲中文无码av在线 | 天天草夜夜 | 在线观看免费的av | 嫩草影院懂你的 | 亚洲爆乳无码精品aaa片蜜桃 | 99精品在线观看视频 | 亚洲欧美日韩精品在线 | 捅肌肌| 亚洲网站视频 | 在线观看欧美日韩 | 久久午夜鲁丝片午夜精品 | 69堂免费视频 | 国产精品无码久久久久久电影 | 女同av在线 | 午夜精品福利一区二区三区蜜桃 | 激情久久五月天 | 40到50岁中老年妇女毛片 |