
PAT
波点兔
这个作者很懒,什么都没留下…
展开
-
Dijkstra与SPFA算法的不同之处对比
SPFA算法 此处为SPFA算法详解 用dis数组记录源点到有向图上任意一点距离,其中源点到自身距离为0,到其他点距离为 INF。将源点入队,并重复以下步骤: 1、队首x出队 2、遍历所有以队首为起点的有向边(x,i),若dis[x]+w(x,i)<dis[i],则更新dis[i] 3、如果点i不在队列中,则i入队 4、若队列为空,跳出循环;否则执行1Dijkstr...原创 2020-02-14 13:07:59 · 1952 阅读 · 1 评论 -
PAT甲级-1111- Online Map(Dijkstra算法+最短路径)
Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is g...原创 2020-02-13 12:21:35 · 358 阅读 · 0 评论 -
PAT甲级-1087-All Roads Lead to Rome(Dijkstra算法+最短路径)
Indeed there are many different tourist routes from our city to Rome. You are supposed to find your clients the route with the least cost while gaining the most happiness.Input Specification:Each in...原创 2020-02-13 12:17:51 · 320 阅读 · 0 评论 -
PAT甲级-1072-Gas Station(Dijkstra算法+最短路径)
A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must guarantee that all the hou...原创 2020-02-13 12:15:09 · 347 阅读 · 0 评论 -
PAT甲级-1030-Travel Plan(Dijkstra算法+最短路径)
A traveler’s map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path b...原创 2020-02-13 12:11:36 · 311 阅读 · 0 评论 -
PAT甲级-1003-Emergency(dfs+最短路径)
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 l...原创 2020-02-13 12:05:52 · 275 阅读 · 0 评论 -
c++ string的erase删除方法
之前不是很清楚c++中string如何删除元素,现在记录一下。(参考自 c++ primer plus 第六版 模版类 string)string中提供的成员函数可以用来删除字符串中的字符,这里主要介绍erase方法erase方法原型1. basic_string & erase(size_type pos=0, size_type n=npos);即从给定起始位置pos处开始删...转载 2020-02-08 18:30:14 · 528 阅读 · 0 评论 -
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...原创 2020-02-08 18:03:20 · 324 阅读 · 0 评论 -
PAT甲级-1033-To Fill or Not to Fill(贪心+图解)
With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different ga...原创 2020-02-08 17:23:23 · 348 阅读 · 0 评论 -
C++字符串查找函数string::find()以及string::npos用法
1、string::find()函数:是一个字符或字符串查找函数,返回类型string::size_type。如果查找成功,返回按照查找规则找到的第一个字符或者子串的位置;如果查找失败,返回string::npos。2、string::npos:是对类型为size_t的元素具有最大可能的值。当这个值在字符串成员函数中的长度或者子长度被使用时,该值表示“直到字符串结尾”。作为返回值他通常被用作表明...原创 2020-02-07 12:04:16 · 3063 阅读 · 0 评论 -
PAT甲级-1092-To Buy or Not to Buy(hash散列)
Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sel...原创 2020-02-06 19:22:04 · 299 阅读 · 0 评论 -
PAT甲级-1050-String Subtraction(hash散列)
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 strings. However, i...原创 2020-02-06 17:58:25 · 322 阅读 · 0 评论 -
PAT甲级-Find Coins(hash+尝试求解)
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,...原创 2020-02-06 17:44:14 · 318 阅读 · 0 评论 -
PAT甲级-1097-Deduplication on a Linked List(链表)
Given 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 a...原创 2020-02-06 16:37:29 · 350 阅读 · 0 评论 -
PAT甲级-1074-Reversing Linked List(链表的局部反转+back()使用)
Given 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,...原创 2020-02-06 14:23:07 · 345 阅读 · 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 give...原创 2020-02-05 16:16:27 · 347 阅读 · 0 评论 -
PAT甲级-1032-Sharing(链表的遍历)
链表的遍历和图的遍历一样,需要设计一个标记变量,标记每个结点node是否被访问过。什么是相同的结点?其实地址相同的结点就是相同结点。什么是公共结点?即遍历完两条单词链,访问过两次的结点。...原创 2020-02-05 14:37:13 · 1552 阅读 · 0 评论 -
PAT甲级-1100-Mars Numbers(字符串)
地球文与火星文转换规则:火星文采用了13进制的转换方式,以下给出了火星文低12,高12位的对应转换规则(加上0,是13位): 1 2 3 4 5 6 7 8 9 10 11 12jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec(低12位) tam, hel, ma...原创 2020-02-04 18:14:54 · 398 阅读 · 0 评论 -
PAT甲级-1071-Speech Patterns(map统计单词次数)
People 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...原创 2020-02-04 16:47:52 · 335 阅读 · 0 评论 -
PAT甲级-1063-Set Similarity(set集合+vector)
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 of distinct...原创 2020-02-04 16:00:54 · 1296 阅读 · 0 评论 -
PAT甲级-1054-The Dominant Color(map统计次数)
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 d...原创 2020-02-03 19:56:08 · 358 阅读 · 0 评论 -
PAT甲级-1047-Student List for Course(vector+段错误问题解决)
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 Sp...原创 2020-02-03 19:27:16 · 413 阅读 · 0 评论 -
PAT甲级-1039-Course List for Student(vector+简单hash)
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 ...原创 2020-02-03 18:45:10 · 239 阅读 · 0 评论 -
getline()函数跟在scanf/cin后容易出现的问题
getline()函数跟在scanf后容易出现getline无法输入字符串的问题,如下:#include<iostream>using namespace std;int main(){ int n;string s; scanf("%d",&n); getline(cin ,s); return 0;}结果:无法输入字符串s原因:用户...原创 2020-02-03 17:02:00 · 586 阅读 · 0 评论 -
PAT甲级-1022-Digital Library(map映射+倒排索引+set)
A 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 a...原创 2020-02-03 16:43:32 · 339 阅读 · 0 评论 -
PAT甲级-1024-Palindromic Number(大整数运算+回文数+加法运算)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers...原创 2020-02-03 14:55:09 · 1351 阅读 · 0 评论 -
C++ 字符串string中的数值运算剖析
在C语言中,实际上字符型数据在内存中是以二进制形式存放的,并不是真正的把一个字符存进内存里。在对字符型数据进行相加减运算的时候,系统会首先会将char型数据以隐形的方式转化成int型数据再进行相加减运算的。因此,由字符型数据在内存的存储方式来看,字符型数据是可以进行数值运算的,对字符型数据做数字运算实际上就是对字符本身对应的ASSIC码进行相应的数值运算。例如:#include<iost...原创 2020-02-03 14:10:05 · 2648 阅读 · 0 评论 -
PAT甲级-1023-Have Fun with Numbers(大整数运算+乘2运算)
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number con...原创 2020-02-03 13:10:39 · 323 阅读 · 0 评论 -
PAT甲级 英文单词汇总
occupy 占用Product of Polynomials 多项式乘积nonzero terms in the polynomial 多项式中的非零项 exponents 指数coefficients 系数respectively 分别的product of A and B 乘积be accurate up to 1 decimal place. 精确到1位小数commas ...原创 2020-02-03 12:40:06 · 3065 阅读 · 1 评论 -
PAT甲级-1080-Graduate Admission(排序)
It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission...原创 2020-02-02 22:51:49 · 258 阅读 · 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 virt...原创 2020-02-02 15:24:32 · 277 阅读 · 0 评论 -
PAT甲级-1075-PAT Judge(排序+疑难分析)
分析:It is then assumed that the user id’s are 5-digit numbers from 00001 to N这句话提示我们id号是从1-N的,因此可以用结构体数组下标来表示练习者的id号,这一点至关重要,它意味着有了每位练习者都有了一个key的地址映射,将一条提交记录匹配到练习者存储位置时,不再用遍历的方式,而直接通过key(id号)就找到了它对应的...原创 2020-02-01 22:03:37 · 393 阅读 · 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 peopl...原创 2020-02-01 15:36:25 · 650 阅读 · 0 评论 -
PAT甲级-1025-PAT Ranking(分数排序+局部排序+全局排序)
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists w...原创 2020-01-31 19:00:06 · 490 阅读 · 0 评论 -
PAT甲级-1016-Phone Bills(排序+map)
A long-distance telephone company charges its customers by the following rules:Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When ...原创 2020-01-31 16:19:37 · 1625 阅读 · 0 评论 -
PAT甲级-1012-The Best Rank(分数排序)
To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - Eng...原创 2020-01-31 10:52:05 · 1990 阅读 · 0 评论 -
PAT甲级-1066-Root of AVL Tree(平衡二叉树)
分析:1、左旋(右子树过高):补充:结点3是忍痛割爱,将自己的左子树砍断,而将紫色集团植入。2、右旋(左子树过高):正好和左旋相反,此处不详述。3、右左旋:先右旋,再左旋4、左右旋:先左旋,再右旋,正好和右左旋相反,此处不详述...原创 2020-01-30 15:56:37 · 1517 阅读 · 0 评论 -
PAT甲级-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 or equal to the node’s key.T...原创 2020-01-29 18:03:46 · 314 阅读 · 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 or equal to the node’s key.T...原创 2020-01-29 16:05:31 · 226 阅读 · 0 评论 -
PAT甲级-1099-Build 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 or equal to the node’s key.T...原创 2020-01-29 15:02:55 · 215 阅读 · 0 评论