- 博客(81)
- 问答 (1)
- 收藏
- 关注
原创 1003 Emergency
1003 EmergencyAs 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 pair of ci
2022-03-11 18:22:55
87
原创 1013 Battle Over Cities
1013 Battle Over CitiesIt 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 highways t
2022-03-09 18:51:04
132
原创 1107 Social Clusters
1107 Social ClustersWhen register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A social cluster is a set of people who have some of their hobbies in common. You are suppos
2022-03-04 11:10:39
99
原创 1066 Root of AVL Tree
1066 Root of AVL Tree根据一组数构建平衡二叉树#include<cstdio>#include<algorithm>using namespace std;struct node{ int val; int height; node* left; node* right;}*root;int n, num;node* newNode(int i){ node* p = new node; p->val =
2022-03-03 16:47:41
277
原创 1099 Build A Binary
1099 Build A Binary Search TreeA 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 contains
2022-03-03 13:33:40
65
原创 1064 Complete Binary Search Tree
1064 Complete Binary Search TreeA 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 contains
2022-03-03 11:50:12
43
原创 1043 Is It a Binary
1043 Is It a Binary Search TreeA 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 contains
2022-03-03 10:01:42
61
原创 1053 Path of Equal Weight
1053 Path of Equal WeightGiven a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the path from R to any leaf node L.Now given an
2022-03-02 17:31:41
206
1
原创 1004 Counting Leaves
1004 Counting LeavesA 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 containing 0<N<100
2022-03-02 15:23:01
95
原创 1094 The Largest Generation
1094 The Largest GenerationA 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 input fil
2022-03-02 14:38:50
90
原创 1090 Highest Price in Supply Chain
1090 Highest Price in Supply Chain19#include<cstdio>#include<cmath>#include<vector>#include<queue>using namespace std;struct node{ int level; int father; vector<int> child;}nodes[100010];int n; //供应链中的总商家数i
2022-03-02 11:41:42
54
原创 1079 Total Sales of Supply Chain
1079 Total Sales of Supply ChainA 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 products fr
2022-03-02 10:42:24
112
原创 1102 Invert a Binary Tree
1102 Invert a Binary TreeInput Specification:Each input file contains one test case. For each case, the first line gives a positive integer N (≤10) which is the total number of nodes in the tree – and hence the nodes are numbered from 0 to N−1. Then N li
2022-03-02 09:02:58
155
原创 1086 Tree Traversals
1086 Tree Traversals Again根据序列的入栈和出栈顺序(即树的前序遍历和中序遍历),构建二叉树并输出树的后序遍历#include<cstdio>#include<stack>#include<string.h>using namespace std;struct node{ int val; node* left; node* right;};stack<int> S;int n;int in[35]
2022-03-01 17:45:38
366
原创 1020 Tree Traversals
1020 Tree TraversalsSuppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree.Input Speci
2022-03-01 17:05:20
65
原创 1091 Acute Stroke
1091 Acute StrokeOne important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, your job is to calculate the volume of the stroke core
2022-03-01 13:54:37
72
原创 1103 Integer Factorization
1103 Integer FactorizationThe K−P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K−P factorization of N for any positive integers N, K and P.Input S
2022-03-01 10:42:28
95
原创 1097 Deduplication on a Linked List
1097 Deduplication on a Linked ListGiven a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of which the value or absolute value of its
2022-03-01 09:07:06
68
原创 1052 Linked List Sorting
1052 Linked List SortingA linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, you are suppos
2022-02-22 16:57:07
52
原创 1032 Sharing
1032 SharingTo store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix. For example, loading and being are stored as showed in
2022-02-22 16:00:08
83
原创 1074 Reversing Linked List
1074 Reversing Linked ListGiven a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→4; if K=4, you must output 4→3→2→1→5→6.
2022-02-22 15:12:40
110
原创 1056 Mice and Rice
1056 Mice and RiceMice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as much rice as possible in order to become a Fat
2022-02-18 15:58:23
187
原创 1051 Pop Sequence
1051 Pop SequenceGiven a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, …, N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if M is 5 and N i
2022-02-18 14:25:44
291
原创 map标题不能少于5个字符
map1.定义map<string, int> scores; //即string到int的映射map<string, set<int> >scores;2.访问通过下标访问map<char,int> mp;mp['c']=20;mp['c']=30; //20被覆盖printf("%d",mp['c']); //输出30通过迭代器访问map<string, int>::iterator sc = scores.be
2022-02-17 18:25:03
296
原创 string
string1.定义string str;2.访问既可以用下标也可以用迭代器如果要读入整个字符串,只可以用cin输出时既可以用cout也可以使用printf,在使用printf时,需要利用c_str()函数将string类型转化为字符数组string迭代器支持直接加减某个数组3.常用函数可之间使用+、-、==、≠、><等符号length()/size()均返回字符串长度insert()insert(pos,string),在pos处插入string字符串str.in
2022-02-17 18:23:47
166
原创 set标题不能少于5个字符
set集合,内部自动有序且不含重复元素1.定义set<int> name;set<set<int> > name;2.访问只能通过迭代器进行访问for (set<int>::iterator it=st.begin(); it != st.end(); it++){ printf("%d\n", *it);}3.常用函数insert()将元素插入set容器中并自动递增排序和去重set<int> st;st.in
2022-02-17 18:22:39
121
原创 vector
vector可简单理解为变长数组1.定义vector<typename> name;例如vector<int> name;vector<char> name;vector<node> name; //node为结构体的类型vector<vector<int> > name; //>和>之间要有空格2.访问通过下标访问若定义某vectorvector<int> vi;可直接用vi
2022-02-17 18:20:14
326
原创 1022 Digital Library
1022 Digital LibraryA Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an unique 7-digit number as its ID. Given any query from a re
2022-02-17 16:29:42
56
原创 1071 Speech Patterns
1071 Speech PatternsPeople often have a preference among synonyms of the same word. For example, some may prefer “the police”, while others may prefer “the cops”. Analyzing such patterns can help to narrow down a speaker’s identity, which is useful when v
2022-02-17 14:52:11
70
原创 1054 The Dominant Color
1054 The Dominant ColorBehind the scenes in the computer’s memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A strictly domina
2022-02-17 14:09:46
124
原创 1100 Mars Numbers
1100 Mars NumbersPeople on Mars count their numbers with base 13:Zero on Earth is called “tret” on Mars.The numbers 1 to 12 on Earth is called “jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec” on Mars, respectively.For the next higher digit
2022-02-16 10:57:33
53
原创 1060 Are They Equal
1060 Are They EqualIf a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123×105 with simple chopping. Now given the number of significant digits on a machine and two float
2022-02-16 09:47:49
138
原创 1063 Set Similarity
1063 Set SimilarityGiven two sets of integers, the similarity of the sets is defined to be Nc/Nt×100%, where Nc is the number of distinct common numbers shared by the two sets, and Nt is the total number of distinct numbers in the two sets. Your job is to
2022-02-15 17:54:50
133
原创 1047 Student List for Course
1047 Student List for CourseZhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses.Input Specification:Each input fil
2022-02-15 16:46:01
82
原创 1039 Course List for Student
1039 Course List for StudentZhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query.Input Specific
2022-02-15 16:05:51
45
原创 1069 The Black Hole
1069 The Black Hole of NumbersFor any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from
2022-02-15 14:42:36
193
原创 1101 Quick Sort
1101 Quick SortThere is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its left and those larger than the pivot to it
2022-02-15 12:27:54
200
原创 1093 Count PAT‘s
1093 Count PAT’sThe string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.Now given any string, you are supposed to te
2022-02-15 10:57:13
45
原创 1029 Median
1029 MedianGiven an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1 = { 11, 12, 13, 14 } is 12, and the median of S2 = { 9, 10, 15, 16, 17 } is 15. The median of two sequences is defined
2022-02-15 10:08:51
227
原创 1044 Shopping in Mar
1044 Shopping in MarsShopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of the diam
2022-02-14 14:38:13
38
空空如也
vector<vector> 排序
2022-03-02
TA创建的收藏夹 TA关注的收藏夹
TA关注的人