
数据结构
文章平均质量分 69
漂流瓶终结者
这个作者很懒,什么都没留下…
展开
-
PAT 1051 Pop Sequence(栈的应用)
Given 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 ...原创 2018-12-11 20:28:43 · 218 阅读 · 0 评论 -
PAT 1047 Student List for Course(哈希)
Zhejiang 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 ...原创 2018-12-11 20:04:18 · 177 阅读 · 0 评论 -
PAT 1046 Shortest Distance
The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.Input Specification: Each input file con...原创 2018-12-11 20:02:18 · 151 阅读 · 0 评论 -
PAT 1064 Complete Binary Search Tree(二叉搜索树)
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 s...原创 2018-12-13 20:36:02 · 186 阅读 · 0 评论 -
PAT 1063 Set Similarity(set应用 交集与并集)
Given 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 o...原创 2018-12-13 20:31:45 · 237 阅读 · 0 评论 -
PAT 1062 Talent and Virtue
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and vi...原创 2018-12-13 20:23:12 · 216 阅读 · 0 评论 -
PAT 1061 Dating
Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm. It took him only a minute to figure out that those strange string...原创 2018-12-13 20:21:47 · 167 阅读 · 0 评论 -
PAT 1060 Are They Equal
If 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 sign...原创 2018-12-13 20:19:46 · 144 阅读 · 0 评论 -
PAT 1059 Prime Factors(质因数分解)
Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1k1×p2k2×⋯×pmkm.Input Specification: Each input file ...原创 2018-12-13 20:12:58 · 210 阅读 · 0 评论 -
PAT 1058 A+B in Hogwarts
If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- as Hagrid explained it to Harry, "Seventeen silver Sickles to a Galleon and twenty-nine Knuts to a S...原创 2018-12-13 20:07:55 · 152 阅读 · 0 评论 -
PAT 1057 Stack(树状数组+二分查找)
Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the top position) and P...原创 2018-12-13 20:05:59 · 292 阅读 · 0 评论 -
PAT 1048 Find Coins(二分)
Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However...原创 2018-12-11 20:10:14 · 192 阅读 · 0 评论 -
PAT 1049 Counting Ones(数学规律)
The task is simple: given any positive integer N, you are supposed to count the total number of 1's in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1's ...原创 2018-12-11 20:15:03 · 208 阅读 · 0 评论 -
PAT 1050 String Subtraction
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1−S2 for any given ...原创 2018-12-11 20:17:17 · 143 阅读 · 0 评论 -
PAT 1055 The World's Richest
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, but concentrate only on the peop...原创 2018-12-11 20:47:05 · 196 阅读 · 0 评论 -
PAT 1054 The Dominant Color
Behind 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 ...原创 2018-12-11 20:43:13 · 156 阅读 · 0 评论 -
PAT 1053 Path of Equal Weight(树的遍历)
Given 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 fr...原创 2018-12-11 20:40:50 · 186 阅读 · 0 评论 -
PAT 1052 Linked List Sorting(链表)
A 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 giv...原创 2018-12-11 20:31:19 · 208 阅读 · 0 评论 -
PAT 1056 Mice and Rice(模拟)
Mice 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 ric...原创 2018-12-13 19:39:31 · 164 阅读 · 0 评论 -
PAT 1039 Course List for Student(哈希表)
Zhejiang 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 ...原创 2018-12-03 21:02:21 · 145 阅读 · 0 评论 -
PAT 1042 Shuffling Machine
Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamble...原创 2018-12-04 20:30:06 · 216 阅读 · 1 评论 -
PAT 1041 Be Unique
Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1,104]. The first one who bets ...原创 2018-12-04 20:25:21 · 158 阅读 · 0 评论 -
PAT 1040 Longest Symmetric String (回文)
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?, the longest symmetric sub-string is s PAT&TAP s, hence you...原创 2018-12-04 20:23:26 · 147 阅读 · 0 评论 -
Trie 字典树
简介 字典树,也称Trie或字母树,指的是某个字符集合对应的有根数。树的每条边上恰好对应一个字符,每个顶点代表从根到该结点的路径所对应的字符串(将所有经过的边上的字符按顺序连接起来)。有时我们也称Trie上的边为转移,顶点为状态。 上图展示了在一棵空Trie中依...原创 2018-08-08 10:56:18 · 170 阅读 · 0 评论 -
树状数组
引言 在解题过程中,我们有时需要维护一个数组的前缀和S[i]=A[i]+A[2]+...+A[i].但是不难发现,如果我们修改了任意一个A[i],S[i],S[i+1]...S[n]都会发生变化。可以说,每次修改A[i]后,调整前缀和S在最坏的情况下会需要O(n)的时间。当n非常大时,程序会运行得非常慢。因此,这里我们引入“树状数组”,它的修改与求和都是O(logn),效率非常高。基本思...转载 2018-08-11 11:06:52 · 342 阅读 · 0 评论 -
set容器
转载自:http://www.cnblogs.com/BeyondAnyTime/archive/2012/08/13/2636375.html1.关于setC++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器,更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结构操作。vector封装数组,list封装了链表,m...转载 2018-08-02 10:01:29 · 1001 阅读 · 1 评论 -
map基本用法
目录引言1.map简介2.map的功能3.使用map4.map的构造函数5. map的大小6.map的基本操作函数引言Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据 处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道。这里说下map内部数...原创 2018-07-22 19:04:55 · 812 阅读 · 0 评论 -
大数四则运算(加、减、乘、除)
大数加法:代码:#include<bits/stdc++.h>#define MAX 1000using namespace std;int Addition(char num1[],char num2[],int sum[]){ int i,j,len; int n2[MAX]={0}; int len1=strlen(num1); ...原创 2018-07-21 19:40:46 · 499 阅读 · 0 评论 -
优先队列 小结
目录一.优先队列概念二.优先队列的头文件三.优先队列的声明四.优先队列的基本操作五.优先队列的排序一.优先队列概念了解完队列之后我们来了解一种特殊的队列--优先队列优先队列是一种特殊的队列,相较于队列它的特殊也是功能最强大之处在于能自动排序。二.优先队列的头文件#include<queue>using namespace std; //命名空...原创 2018-07-20 11:02:11 · 1127 阅读 · 0 评论 -
队列 简单小结
目录一.队列的基本概念二.队列的操作一.队列的基本概念队列(queue)也是一种线性表,它的特性是先进先出,插入在一端,删除在另一端。就像排队一样,刚来的人入队(push)要排在队尾(rear),每次出队(pop)的都是队首(front)的人。队列(Queue)与栈一样,是一种线性存储结构,它具有如下特点:队列中的数据元素遵循“先进先出”(First In First Ou...原创 2018-07-20 10:15:15 · 871 阅读 · 0 评论 -
vector容器 浅析
目录一.基本概念二.用法一.基本概念vector(向量): C++中的一种数据结构,确切的说是一个类.它相当于一个动态的数组,当程序员无法知道自己需要的数组的规模多大时,用其来解决问题可以达到最大节约空间的目的.二.用法1.文件包含:#include<vector>还有一定要加上using namespace std;2.声明:例:声明一个int...原创 2018-07-20 10:00:24 · 267 阅读 · 0 评论 -
1043 Is It a Binary Search Tree(树)
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 su...原创 2018-12-04 20:36:18 · 170 阅读 · 0 评论 -
PAT 1044 Shopping in Mars(前缀和+二分)
Shopping 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...原创 2018-12-04 20:43:31 · 247 阅读 · 0 评论 -
PAT 1027 Colors in Mars
1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 di...原创 2018-11-27 18:50:28 · 148 阅读 · 1 评论 -
PAT 1037 Magic Coupon
The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning that when you use this coupon with a product, you may get N times the value of that product b...原创 2018-12-03 20:02:46 · 175 阅读 · 0 评论 -
PAT 1038 Recover the Smallest Number
Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-022...原创 2018-12-03 19:36:02 · 144 阅读 · 0 评论 -
PAT 1036 Boys vs Girls
This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.Input Specification: Each input file contains one...原创 2018-12-03 19:34:29 · 193 阅读 · 0 评论 -
PAT 1035 Password
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L ...原创 2018-12-03 19:32:34 · 160 阅读 · 0 评论 -
PAT 1034 Head of a Gang(并查集)
One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call between A and B, we say that A and B is related. The weight of a relation is defined to be t...原创 2018-12-03 19:30:47 · 289 阅读 · 0 评论 -
PAT 1032 Sharing (哈希表)
To 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,...原创 2018-12-03 19:22:33 · 161 阅读 · 0 评论