![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法笔记
文章平均质量分 77
二脸
这个作者很懒,什么都没留下…
展开
-
a1005 Spell It Right (string应用)
1005 Spell It Right (20 分)Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each input file contains one test case. Each case occupies one line whi原创 2022-02-28 15:55:58 · 63 阅读 · 0 评论 -
a1004 Counting Leaves (DFS)
1004 Counting Leaves (30 分)A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one test case. Each case starts with a line containing0&l.原创 2022-02-28 15:42:06 · 63 阅读 · 0 评论 -
a1003 Emergency (dijkstra + dfs)
1003 Emergency (25 分)As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pa原创 2022-02-28 15:40:12 · 66 阅读 · 0 评论 -
a1076 Forwards on Weibo (DFS、BFS)
1076 Forwards on Weibo (30 分)Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weib原创 2022-02-27 20:53:57 · 84 阅读 · 0 评论 -
a1021 Deepest Root (图的遍历、DFS)
1021 Deepest Root (25 分)A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is calledthe deepest root.I.原创 2022-02-27 15:56:24 · 188 阅读 · 0 评论 -
a1013 Battle Over Cities (图的遍历 DFS)
1013 Battle Over Cities (25 分)It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other hi原创 2022-02-27 14:41:17 · 143 阅读 · 0 评论 -
1076 Forwards on Weibo(BFS)
1076 Forwards on Weibo (30 分)Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weib原创 2022-02-26 20:38:51 · 236 阅读 · 0 评论 -
a1034 Head of a Gang (DFS、并查集)
1034 Head of a Gang (30 分)One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call betweenAandB, we say thatAandBis related. The weight of a relation is defined to be the total time length of all ...原创 2022-02-26 18:59:47 · 145 阅读 · 0 评论 -
pat1107 Social Clusters 并查集
1107 Social Clusters (30 分)When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. Asocial clusteris a set of people who have some of their hobbies in common. You ar..原创 2022-02-26 13:11:05 · 78 阅读 · 0 评论 -
1099 Build A Binary Search Tree(树的遍历)
1099 Build A Binary Search Tree (30 分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node原创 2022-02-25 23:53:24 · 418 阅读 · 0 评论 -
pat1064 Complete Binary Search Tree(树的遍历)
1064 Complete Binary Search Tree (30 分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a n...原创 2022-02-25 22:48:00 · 157 阅读 · 0 评论 -
pat甲级1043 静态二叉树(BST)
由于指针学得不是很好,就尝试把《算法笔记》上用的指针树,改为静态二叉链表。大体思路:把这个输入的数组,用insert方法,形成一个BST,root保存的是根节点,然后对这个形成的树分别进行先序遍历,和先序镜像遍历;如果原数组和先序遍历后的数组相等,则说明原数组是BST,如果原数组和先序镜像遍历后的数组相等,则说明是镜像BST;有两个测试点答案错误,过段时间再回头看看吧;反思:刚开始把index放在了Node[index]后面,这就导致了root=index+1,root变为第二个元素了,就不再.原创 2022-02-24 17:45:24 · 558 阅读 · 0 评论 -
pat1053Path of Equal Weight (DFS)
1053 Path of Equal Weight (30 分)Given a non-empty tree with rootR, and with weightWiassigned to each tree nodeTi. Theweight of a path fromRtoLis defined to be the sum of the weights of all the nodes along the path fromRto any leaf nodeL.N...原创 2022-02-25 19:12:52 · 177 阅读 · 0 评论 -
pat1094 The Largest Generation (DFS、BFS)
1094 The Largest Generation (25 分)A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population.Input Specification:Each原创 2022-02-25 16:40:20 · 123 阅读 · 0 评论 -
pat1106 Lowest Price in Supply Chain (DFS)
1106 Lowest Price in Supply Chain (25 分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys p原创 2022-02-25 15:18:09 · 56 阅读 · 0 评论 -
pat1079 Total Sales of Supply Chain (DFS)
1079 Total Sales of Supply Chain (25 分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys pr原创 2022-02-25 14:30:48 · 49 阅读 · 0 评论 -
pat1090 Highest Price in Supply Chain (DFS)
1090 Highest Price in Supply Chain (25 分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys原创 2022-02-25 13:59:47 · 68 阅读 · 0 评论 -
pat甲级1102 Invert a Binary Tree (树的遍历)
1102 Invert a Binary Tree (25 分)The following is from Max Howell @twitter:Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off.Now it's your turn to prove that YOU CAN ..原创 2022-02-25 11:34:50 · 249 阅读 · 0 评论 -
pat1086 Tree Traversals Again(树的遍历)
初始版本:不知道最后一个测试点为什么一直段错误#include <iostream>#include "stack"#include "algorithm"#include "vector"using namespace std;int n;int pre[30],in[30];vector<int> post;void postOrder(int preL,int preR,int inL,int inR){ if (inL > inR) r原创 2022-02-25 00:49:45 · 160 阅读 · 0 评论 -
pat甲级1020 Tree traversals (后序+中序 ->层序)
第一次做不出来,学习了柳神的解法pre函数的参数 root:根节点在后序中的位置;start:子树在中序中开始位置序号;end:子树在中序中结束的位置序号index:从0开始,每个节点的序号左边是2*index+1,右边是2*index;层序遍历即可按照index从小到大的顺序输出#include <iostream>#include "map"#include "vector"#include "algorithm"using namespace std;ve.原创 2022-02-24 22:34:03 · 455 阅读 · 0 评论 -
9.6.3并查集:好朋友
算法笔记并查集:好朋友原创 2022-02-24 20:55:52 · 171 阅读 · 0 评论