
pat岁月
qq2285580599
这个作者很懒,什么都没留下…
展开
-
程序设计基础83 fill二维数组!!!
scanf("%d %d %d %d", &N, &M, &c1, &c2);//Important!!!!!!!!!fill(G[0], G[0] + max_n*max_n, INF);for (int i = 0; i < N; i++) { scanf("%d", &single_weight[i]);}原创 2018-12-08 20:21:30 · 163 阅读 · 0 评论 -
程序设计基础82 图的BFS
所有BFS都是在que.push()之后设置true的。原创 2018-12-08 19:18:41 · 118 阅读 · 0 评论 -
程序设计基础81 图之无向图防止回头和访问通向已访问结点的路径
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 between A and B, we say that A and B is related. The weight of a...原创 2018-12-08 10:27:31 · 153 阅读 · 0 评论 -
程序设计基础80 并查集如何连结数据
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. A social cluster is a set of...原创 2018-12-07 17:25:44 · 178 阅读 · 0 评论 -
程序设计基础79 给定二叉排序树结构和数组求整棵树
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...原创 2018-12-06 21:00:23 · 192 阅读 · 0 评论 -
程序设计基础78 tips 关于代码整洁性问题
1043 Is It a Binary Search Tree (25 分)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...原创 2018-12-06 11:18:03 · 197 阅读 · 0 评论 -
程序设计基础77 DFS遍历树时第一个形参表示的结点不一定是待检测的
1053 Path of Equal Weight (30 分)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 o...原创 2018-12-04 18:49:10 · 148 阅读 · 0 评论 -
程序设计基础76 已知前序,后序和层序遍历序列与中序遍历序列组合得到树的方法
#include<cstdio>#include<queue>using namespace std;const int max_n = 50;int N = 0;int level[max_n];int in[max_n];int post[max_n];bool flag[max_n] = { false };struct node { int d...原创 2018-12-04 09:08:44 · 204 阅读 · 0 评论 -
程序设计基础75 tips 广度搜索细节问题
1,记住在scanf("%c",&a)输入一个字符型变量时,若是之前有输入回车,一定要用getchar()吸收。2,进行广度和深度优先搜索代码的调试时,还有那些输入数据较多的代码的调试时,一定要一步一步地,子函数都要进入,每一条语句都要看,能够在执行指向语句前及时改正错误,否则一旦错过去,可能得重新输入大量数据或者重新执行复杂的步骤。...原创 2018-12-03 11:17:41 · 135 阅读 · 0 评论 -
程序设计基础74 链表之区分无效结点,删除结点与保留结点的方法
1097 Deduplication on a Linked List (25 分)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,...原创 2018-12-02 19:10:23 · 175 阅读 · 0 评论 -
程序设计基础73 链表之特判
1052 Linked List Sorting (25 分)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 pointe...原创 2018-12-02 15:23:40 · 157 阅读 · 0 评论 -
程序设计基础72 链表基础
1074 Reversing Linked List (25 分)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 y...原创 2018-12-02 10:27:31 · 5699 阅读 · 4 评论 -
程序设计基础71 STL之queue中的小问题
1056 Mice and Rice (25 分)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 m...原创 2018-12-01 17:35:22 · 231 阅读 · 0 评论 -
程序设计基础70 STL之扫描长字符串问题
1071 Speech Patterns (25 分)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 ...原创 2018-11-30 15:37:43 · 231 阅读 · 0 评论 -
程序设计基础69 STL之map
1100 Mars Numbers (20 分)People on Mars count their numbers with base 13:Zero on Earth is called "tret" on Mars. The numbers 1 to 12 on Earch is called "jan, feb, mar, apr, may, jun, jly, aug, sep...原创 2018-11-30 10:17:54 · 151 阅读 · 0 评论 -
程序设计基础68 STL之string
1060 Are They Equal (25 分)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. No...原创 2018-11-30 07:07:01 · 123 阅读 · 0 评论 -
程序设计基础67 STL之set中查找相同元素最后不用平方级轮子
1063 Set Similarity (25 分)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 N...原创 2018-11-29 17:16:26 · 171 阅读 · 0 评论 -
程序设计基础66 STL之vector中大规模数据排序最好不用string
1047 Student List for Course (25 分)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 na...原创 2018-11-29 16:04:56 · 264 阅读 · 0 评论 -
程序设计基础65 STL之散列存储字符与二维vector的范围
1039 Course List for Student (25 分)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 co...原创 2018-11-29 09:56:19 · 147 阅读 · 0 评论 -
程序设计基础64 数学问题之关于int的范围之错
1024 Palindromic Number (25 分)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...原创 2018-11-28 19:18:39 · 262 阅读 · 0 评论 -
程序设计基础63 数学问题之大整数乘法
1023 Have Fun with Numbers (20 分)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 happe...原创 2018-11-28 11:16:14 · 312 阅读 · 0 评论 -
程序设计基础62 数学问题平方探查法
The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be H(key)=key%TSiz...原创 2018-11-27 10:18:26 · 169 阅读 · 0 评论 -
程序设计基础61 tips long long类型与abs是矛盾的
不能将abs用于long long类型的数据,pat的c++编译器会报错。原创 2018-11-26 21:46:02 · 1319 阅读 · 0 评论 -
程序设计基础60 数学问题之算有多少个1
1049 Counting Ones (30 分)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 bei...原创 2018-11-26 15:55:40 · 222 阅读 · 0 评论 -
程序设计基础59 数学问题数列片段和
1104 Sum of Number Segments (20 分)Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence { 0.1, 0.2, 0.3, 0.4 }, we have 10 segme...原创 2018-11-26 08:16:54 · 143 阅读 · 0 评论 -
程序设计基础58 递推非暴力
1101 Quick Sort (25 分)There 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 p...原创 2018-11-25 20:17:38 · 131 阅读 · 0 评论 -
程序设计基础57 随机选择算法,找出数组第n/2大,并返回后一半减去前一半的值,复杂度o(n)
#include<cstdio>#include<cstdlib>#include<ctime>#include<algorithm>using namespace std;const int max_n = 100010;int A[max_n], n;int randPartition(int A[], int left, int...原创 2018-11-25 19:18:21 · 190 阅读 · 0 评论 -
程序设计基础56 tips关于以stdio为头文件的注意事项
以stdio为头文件时,在main函数外声明数组时,数组长度用数字而不要用变量。#include<stdio.h>#include<string.h>const int max_n = 100100;const int MOD = 1000000007;char str[max_n]; //这里极易编译出错,因为这里应该用数字...原创 2018-11-25 18:36:09 · 134 阅读 · 0 评论 -
程序设计基础55 two_pointers解决内存超限
1029 Median (25 分)Given 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,...原创 2018-11-25 11:06:36 · 164 阅读 · 0 评论 -
程序设计基础54 two_pointers PAT A1089
1089 Insert or Merge (25 分)According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one...原创 2018-11-24 19:45:23 · 118 阅读 · 0 评论 -
程序设计基础53 two_pointers如何不超时
1085 Perfect Sequence (25 分)Given a sequence of positive integers and another positive integer p. The sequence is said to be a perfect sequence if M≤m×p where M and m are the maximum and minimum num...原创 2018-11-24 16:22:21 · 121 阅读 · 0 评论 -
程序设计基础52 二分关于连续串的和的表示法
1044 Shopping in Mars (25 分)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 cha...原创 2018-11-24 07:06:46 · 143 阅读 · 0 评论 -
程序设计基础51 二分关于进制转换与溢出的处理
1010 Radix (25 分)Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes, if 6 is a decimal number and 110 is a binary number.Now for any pa...原创 2018-11-23 16:35:29 · 343 阅读 · 0 评论 -
程序设计基础51 二分注意数值越界
1085 Perfect Sequence (25 分)Given a sequence of positive integers and another positive integer p. The sequence is said to be a perfect sequence if M≤m×p where M and m are the maximum and minimum num...原创 2018-11-23 14:52:58 · 145 阅读 · 0 评论 -
程序设计基础50 取余公式
版权声明:转载请注明出处 http://blog.youkuaiyun.com/TwT520Ly https://blog.youkuaiyun.com/TwT520Ly/article/details/53980196 基本性质:若p|(a-b),则a≡b(%p)(a%p) = (...转载 2018-11-23 11:07:26 · 489 阅读 · 0 评论 -
程序设计基础49 PAT A1038
1038 Recover the Smallest Number (30 分)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 recove...原创 2018-11-22 20:13:39 · 134 阅读 · 0 评论 -
程序设计基础48 PAT A1033
1033 To Fill or Not to Fill (25 分)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...原创 2018-11-22 16:41:24 · 145 阅读 · 0 评论 -
程序设计基础47 PAT A1070
1070 Mooncake (25 分)Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes according to the ...原创 2018-11-21 20:44:07 · 212 阅读 · 0 评论 -
程序设计基础46 tips 关于abs的使用
在codeup墓地里面要使用abs必须要用#include<cmath>原创 2018-11-21 17:55:46 · 191 阅读 · 0 评论 -
程序设计基础45 PAT A1048
1048 Find Coins (25 分)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 coi...原创 2018-11-21 16:45:38 · 224 阅读 · 0 评论