- 浏览: 36683 次
- 性别:
- 来自: 杭州
最新评论
统计树的每一层上叶子节点的个数
Sample Input
2 1
01 1 02
Sample Output
0 1
#include <iostream> #include <iomanip> #include <string> #include <map> #include <vector> using namespace std; void fun(vector<string> &v, map<string,vector<string>> &MapTree) { vector<string> next; int leaf = 0; vector<string>::iterator iter = v.begin(); while(iter != v.end()) { map<string,vector<string>>::iterator iterMap = MapTree.find(*iter); if (iterMap != MapTree.end()) { vector<string> vec = iterMap->second; if (vec.size() == 0) { leaf++; } else { next.insert(next.end(),vec.begin(),vec.end()); } } else { leaf++; } iter++; } cout<<" "<<leaf; if (next.size() == 0) { return; } fun(next,MapTree); } int main() { map<string,vector<string>> MapTree; int N,M; cin>>N>>M; while(M--) { string str; int K; vector<string> VNode; cin>>str>>K; while(K--) { string strNode; cin>>strNode; VNode.push_back(strNode); } MapTree[str] = VNode; } map<string,vector<string>>::iterator iter = MapTree.find("01"); if (iter != MapTree.end()) { vector<string> v = iter->second; if (v.size() > 0) { cout<<"0"; fun(v, MapTree); } else { cout<<"1"; } } else { cout<<"1"; } return 0; }
发表评论
-
PAT1013 Battle Over Cities
2012-11-29 23:59 774Sample Input 3 2 3 1 2 1 3 ... -
PAT1003 Emergency
2012-11-29 23:46 664Sample Input 5 6 0 2 1 2 1 ... -
PAT1041 Be Unique
2012-11-23 23:43 762找出只出现过一次的数,用各种排序必然超时,需要用数组做hash ... -
PAT1042 Shuffling Machine
2012-11-23 23:42 734扑克洗牌 #include < ... -
PAT1040 Longest Symmetric String
2012-11-23 23:41 960求最长回文子串 #include < ... -
PAT1036 Boys vs Girls
2012-11-23 23:41 716Sample Input 1: 3 Joe M Mat ... -
PAT1035 Password
2012-11-23 23:40 618Sample Input 1: 3 Team0000 ... -
PAT1031 Hello World for U
2012-11-22 23:54 656Sample Input: helloworld! S ... -
PAT1029 Median
2012-11-22 23:54 654用标准库的排序全部超时,需要自己实现,另外还不能用cin co ... -
PAT1028 List Sorting
2012-11-22 23:53 809用vector最后一个用例超时了。。。 Sample ... -
PAT1027 Colors in Mars
2012-11-22 23:52 625Sample Input 15 43 71 Samp ... -
PAT1025 PAT Ranking
2012-11-22 23:51 774Sample Input: 2 5 123456789 ... -
PAT1023 Have Fun with Numbers
2012-11-21 23:55 687大数的相加 比较两个字符串中字符完全相同 Sa ... -
PAT1020 Tree Traversals
2012-11-21 23:54 654已知中序遍历 后序遍历,求层次遍历 Sample In ... -
PAT1019 General Palindromic Number
2012-11-21 23:53 539十进制转任意进制,并比较是否是回文数 Sample I ... -
PAT1037 Magic Coupon
2012-11-21 15:46 664Sample Input: 4 1 2 4 -1 ... -
PAT1038 Recover the Smallest Number
2012-11-20 23:52 1670由一道面试题改的 把数组排成最小的数 不同之处是这 ... -
PAT1024 Palindromic Number
2012-11-20 23:51 650Sample Input 1: 67 3 Sampl ... -
PAT1015 Reversible Primes
2012-11-19 23:51 771十进制转任意进制 假设十进制数为number,转 ... -
PAT1012 The Best Rank
2012-11-19 23:50 927四门功课,输出排名最高的是哪个 Sample Inpu ...
相关推荐
1004. Counting Leaves (30) 来自:http://blog.csdn.net/sunbaigui/article/details/8657008
A family hierarchy等级 is usually presented by a pedigree tree系谱树. Your job is to count those family members who have no child.
为了记录我在准备PAT甲级的练习,特开此页。...Counting Leaves https://blog.csdn.net/weixin_42426496/article/details/104222455 1006 Sign In and Sign Out https://blog.csdn.net/weixin_42426496/article/detai
To reflect that, and to make the Counting Practices Manual (CPM) even more attractive as a reference manual, the Counting Practices Committee (CPC) decided to restructure CPM 4.2 into four parts: ...
The Function Point Counting Practices Manual is the definitive description of the Function Pointing Counting Standard. Several versions of the manual are available, each describing the standard or ...
Function Point Counting Practices Manual (功能点计算实践手册)4.3版
程序员 刷题 judge My PAT Solutions 记录我在刷 PAT 甲级时遇到的一些问题以及总结的经验。做法可能不是最优的,如有更...Leaves(30 分) 解题思路 C++: 使用 vector tree[MAX_N] 的形式保存各个 ID 结点拥有的子结点
3D人员计数例程系统文档
The Pleasures of Counting 1996 © Cambridge University Press 1996
These practices are a compilation of acceptable proce- dures for cycle-counting methods employed in fatigue analysis. This standard does not intend to recommend a particular method.
Function Point Counting Practices Manual 4.1.1 版本。 来自IFPUG,权威资料 The primary objectives of the IFPUG Counting Practices Manual, Release 4.1, are to • Provide a clear and detailed description...
Counting源代码统计器,对开发的代码进行统计,辅助开发者进行开发,也可以用于软件测试时对代码的统计
To reflect that, and to make the Counting Practices Manual (CPM) even more attractive as a reference manual, the Counting Practices Committee (CPC) decided to restructure CPM 4.2 into four parts: ...
可以统计source有效行,空行,注释行,文件的大小,统计的文件数目的工具
论文Attentional Neural Fields for Crowd Counting,侵删
Zhang_Cross-Scene_Crowd_Counting_2015_CVPR_paper.pdf
输出一段字串中的字符数——程序很小,第一次上传,大家多支持!
统计代码量的工具 软件开发必备 简单易操作
利用差分盒计数法计算图像分维数,利用matlab语言编写
一个统计代码行的很简单很适用的小工具-a statistical line of code is very simple and very applicable to the small tools