![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
pat
帆的孤独啊
这个作者很懒,什么都没留下…
展开
-
Hanoi
Hanoi 塔问题是印度的一个古老的传说。开天辟地的神勃拉玛在一个庙里留下了三根金刚石的棒,第一根上面套着64 个圆的金片,最大的一个在底下,其余一个比一个小,依次叠上去,庙里的众僧不倦地把它们一个个地从这根棒搬到另一根棒上,规定可利用中间的一根棒作为帮助,但每次只能搬一个,而且大的不能放在小的上面。请编写程序,把A 柱上的n 个金片,搬动到C 柱(中间可以使用B 柱),使得搬动的次数最少。输入金...原创 2018-03-14 16:36:37 · 163 阅读 · 0 评论 -
1086. Tree Traversals Again
An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stac...原创 2018-03-11 17:43:50 · 129 阅读 · 0 评论 -
1098. Insertion or Heap Sort
According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. At each iteration, insertion sort removes one element from the input data...原创 2018-03-11 15:18:57 · 109 阅读 · 0 评论 -
1010. Radix
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 pair of positive inte...原创 2018-03-03 16:05:30 · 129 阅读 · 0 评论 -
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 the node's key.The right subtre...原创 2018-03-10 21:39:13 · 91 阅读 · 0 评论 -
1065. A+B and C (64bit)
Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C.Input Specification:The first line of the input gives the positive number of test cases, T (<=10). Then T...原创 2018-03-10 21:04:43 · 209 阅读 · 1 评论 -
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 significa...原创 2018-03-10 20:39:53 · 192 阅读 · 0 评论 -
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 = p1^k1 * p2^k2 *…*pm^km.Input Specification:Each input file contains one test case whic...原创 2018-03-10 15:41:46 · 119 阅读 · 0 评论 -
重定位
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<stack>#include<vector>#include<iostream>#include<algorithm>原创 2018-03-10 15:40:55 · 104 阅读 · 0 评论 -
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...原创 2018-03-10 14:13:59 · 193 阅读 · 0 评论 -
图的BFS遍历
#include<map>#include<iostream>#include<string>#include<vector>#include<queue>using namespace std;const int maxn=1000;/* 深度优先:利用递归或者栈 广度优先:队列 注意一点:标记数组inq[]记录的...原创 2018-02-23 17:33:24 · 281 阅读 · 0 评论 -
1015. Reversible Primes
A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a pr...原创 2018-03-04 16:54:21 · 138 阅读 · 0 评论 -
1003. Emergency
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...原创 2018-03-11 20:00:59 · 113 阅读 · 0 评论 -
1072. Gas Station
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...原创 2018-03-11 21:49:11 · 145 阅读 · 0 评论 -
最长回文子序列(double point)
int main(){ //freopen("E:\\learn\\inputs.txt","r",stdin); //枚举每个点,向两端扩展 string a; int ans=0,temp=0; getline(cin,a); for(int i=0;i<a.length();i++){ temp=1; int j=i-1,k=i+1; while(j>=...原创 2018-03-14 10:22:52 · 358 阅读 · 0 评论 -
最长公共子序列
#include<stack>#include<vector>#include<iostream>#include<algorithm>#include<math.h>#include<queue>#include<map>#include<string>#include原创 2018-03-14 09:57:38 · 92 阅读 · 0 评论 -
后缀表达式用栈求值
#include<stack>#include<vector>#include<iostream>#include<algorithm>#include<math.h>#include<queue>#include<map>#include<string>#include原创 2018-03-14 09:35:41 · 825 阅读 · 0 评论 -
1022. Digital Library (30)
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...原创 2018-03-05 22:01:44 · 93 阅读 · 0 评论 -
1087. All Roads Lead to Rome
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 inpu...原创 2018-03-12 19:12:59 · 229 阅读 · 0 评论 -
01背包问题
辰辰是个很有潜能、天资聪颖的孩子,他的梦想是称为世界上最伟大的医师。 为此,他想拜附近最有威望的医师为师。医师为了判断他的资质,给他出了一个难题。 医师把他带到个到处都是草药的山洞里对他说: “孩子,这个山洞里有一些不同的草药,采每一株都需要一些时间,每一株也有它自身的价值。 我会给你一段时间,在这段时间里,你可以采到一些草药。如果你是一个聪明的孩子,你应该可以让采到的草药的总价值最大。” 如果你...原创 2018-03-18 21:21:32 · 147 阅读 · 0 评论 -
1022. Digital Library
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...原创 2018-03-05 15:34:24 · 103 阅读 · 0 评论 -
1066. Root of AVL Tree
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is...原创 2018-03-18 18:09:33 · 155 阅读 · 0 评论 -
1074. Reversing Linked List(双指针调动)
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 ...原创 2018-03-12 15:30:49 · 108 阅读 · 0 评论 -
1017. Queueing at Bank
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow li...原创 2018-03-04 22:17:28 · 155 阅读 · 0 评论 -
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-02-23 16:55:03 · 143 阅读 · 0 评论 -
DP动态规划
#include<stdio.h>#include<algorithm>#include<math.h>#include<iostream>#include<string.h>#include<vector>#include<queue>using namespace std;/* 动态规划:利用原创 2018-03-01 20:34:50 · 126 阅读 · 0 评论 -
利用优先队列计算最短WPL
#include<stdio.h>#include<queue>#include<vector>#include<math.h>#include<algorithm>using namespace std;/* huffman实现:利用堆 eg:求最小带权路径*/priority_queue<int,vecto...原创 2018-02-23 10:35:40 · 267 阅读 · 0 评论 -
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 contains ...原创 2018-03-08 14:15:04 · 95 阅读 · 0 评论 -
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-0229-8...原创 2018-03-07 20:00:23 · 79 阅读 · 0 评论 -
1065. 单身狗
“单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱。输入格式:输入第一行给出一个正整数N(<=50000),是已知夫妻/伴侣的对数;随后N行,每行给出一对夫妻/伴侣——为方便起见,每人对应一个ID号,为5位数字(从00000到99999),ID间以空格分隔;之后给出一个正整数M(<=10000),为参加派对的总人数;随后一行给出这M位客...原创 2018-02-27 17:01:53 · 161 阅读 · 0 评论 -
1068. 万绿丛中一点红(20)
对于计算机而言,颜色不过是像素点对应的一个24位的数值。现给定一幅分辨率为MxN的画,要求你找出万绿丛中的一点红,即有独一无二颜色的那个像素点,并且该点的颜色与其周围8个相邻像素的颜色差充分大。输入格式:输入第一行给出三个正整数,分别是M和N(<= 1000),即图像的分辨率;以及TOL,是所求像素点与相邻点的颜色差阈值,色差超过TOL的点才被考虑。随后N行,每行给出M个像素的颜色值,范围在...原创 2018-02-27 14:42:21 · 86 阅读 · 0 评论 -
1049. 数列的片段和
给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段。例如,给定数列{0.1, 0.2, 0.3, 0.4},我们有(0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0.4) (0.3) (0.3, 0.4) (0.4) 这10个片段。给定正整数数列,求出全部片段包含的所有的...原创 2018-02-27 14:40:01 · 101 阅读 · 0 评论 -
Dijkstra算法
#include<stdio.h>#include<string.h>#include<vector>//涉及到和录入顺序相关的首先想到用vector接受#include<algorithm>#include<string>#include<iostream>#include<map>using na原创 2018-02-26 16:22:31 · 163 阅读 · 0 评论 -
1080. MOOC期终成绩
对于在中国大学MOOC(http://www.icourse163.org/)学习“数据结构”课程的学生,想要获得一张合格证书,必须首先获得不少于200分的在线编程作业分,然后总评获得不少于60分(满分100)。总评成绩的计算公式为 G = (G期中x 40% + G期末x 60%),如果 G期中 > G期末;否则总评 G 就是 G期末。这里 G期中 和 G期末 分别为学生的期中和期末成绩。...原创 2018-02-26 15:28:22 · 480 阅读 · 0 评论 -
1079. 延迟的回文数
给定一个 k+1 位的正整数 N,写成 ak...a1a0 的形式,其中对所有 i 有 0 <= ai < 10 且 ak > 0。N 被称为一个回文数,当且仅当对所有 i 有 ai = ak-i。零也被定义为一个回文数。非回文数也可以通过一系列操作变出回文数。首先将该数字逆转,再将逆转数与该数相加,如果和还不是一个回文数,就重复这个逆转再相加的操作,直到一个回文数出现。如果一个...原创 2018-02-26 14:22:30 · 223 阅读 · 0 评论 -
1075. 链表元素分类(25)
时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, Yue给定一个单链表,请编写程序将链表元素进行分类排列,使得所有负值元素都排在非负值元素的前面,而[0, K]区间内的元素都排在大于K的元素前面。但每一类内部元素的顺序是不能改变的。例如:给定链表为 18→7→-4→0→5→-6→10→11→-2,K为10,则输出应该为 -4→-6→-2→7...原创 2018-02-26 13:44:56 · 156 阅读 · 0 评论 -
1039. 到底买不买
小红想买些珠子做一串自己喜欢的珠串。卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖。于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要的珠子?如果是,那么告诉她有多少多余的珠子;如果不是,那么告诉她缺了多少珠子。为方便起见,我们用[0-9]、[a-z]、[A-Z]范围内的字符来表示颜色。例如在图1中,第3串是小红想做的珠串;那么第1串可以买,因为包含了全部她想要的珠子,还多...原创 2018-02-26 10:09:12 · 169 阅读 · 0 评论 -
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-03-08 14:31:51 · 100 阅读 · 0 评论 -
动态二叉树后序和中序建树并层序遍历
#include<stdio.h>#include<queue>//给出后序和中序求层序using namespace std;int ins[31],posts[31],n;struct Node{ int data; Node *lchild; Node *rchild;};void Layer(Node *root){//保证输出时没有空格 ...原创 2018-02-20 16:40:14 · 584 阅读 · 0 评论 -
DFS求给定权值的路径并按非递增顺序输出
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 from R to...原创 2018-02-20 18:27:06 · 303 阅读 · 0 评论