题目 In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less than or equal to (in a mi…
In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less than or equal to (in a min h…
题意分析: 给出一个1000以内的整数N,以及N个整数,并且这N个数是按照完全二叉树的层序遍历输出的序列,输出所有的整条的先序遍历的序列(根 右 左),以及判断整棵树是否是符合堆排序的规则(判断是大顶堆,小顶堆,不是堆) 题解分析: 由于给出的整数序列是按照完全二叉树的层序遍历,所以不存在中间有空的节点,并且层序遍历满足1~N的节点顺序正好方便我们一边输入一边建立完全二叉树,之后就是正常的先序遍历(这题要求根 右 左),有所区别的是最后的输出每次到达最后一个叶子节点的时候都需要输出一遍整条序列,…
 Stamps  The government of Nova Mareterrania requires that various legal documents have stamps attached to them so that the government can derive revenue from them. In terms of recent legislation, each class of document is limited in the number of st…
In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less than or equal to (in a min h…
https://pintia.cn/problem-sets/994805342720868352/problems/1071785408849047552 In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is eithe…
题目链接:1155 Heap Paths (30 分) In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less…
Description An abandoned country has n(n≤100000) villages which are numbered from 1 to n. Since abandoned for a long time, the roads need to be re-built. There are m(m≤1000000) roads to be re-built, the length of each road is wi(wi≤1000000). Guarante…
深搜,从一点向各处搜找到全部能走的地方. Problem Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on…
DFS 深搜专题 入门典例 -- 凌宸1642 深度优先搜索 是一种 枚举所有完整路径以遍历所有情况的搜索方法 ,使用 递归 可以很好的实现 深度优先搜索. 1 最大价值 题目描述 ​ 有 n 件物品,每件物品的重量为 w[i] , 价值为 c[i] .现在需要选出若干件物品放入一个容器为 V 的背包中,使得在选入背包的物品重量和不超过容量 V 的前提下 ,让背包中的物品的价值之和最大,求最大价值.(1 ≤ n≤ 20 ) 输入描述: ​ 第一行输入物品总数 n 和 背包容量 v . ​ 第二行…
[编程题] 黑白树 时间限制:1秒 空间限制:32768K 一棵n个点的有根树,1号点为根,相邻的两个节点之间的距离为1.树上每个节点i对应一个值k[i].每个点都有一个颜色,初始的时候所有点都是白色的. 你需要通过一系列操作使得最终每个点变成黑色.每次操作需要选择一个节点i,i必须是白色的,然后i到根的链上(包括节点i与根)所有与节点i距离小于k[i]的点都会变黑,已经是黑的点保持为黑.问最少使用几次操作能把整棵树变黑. 输入描述: 第一行一个整数n (1 ≤ n ≤ 10^5) 接下来n-1…
[题目链接:HDOJ-2952] Counting Sheep Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2476    Accepted Submission(s): 1621 Problem Description A while ago I had trouble sleeping. I used to lie awake,…
Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only…
Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18201   Accepted: 9192 Description Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100…
题目链接: 这个题目非常好,有难度:能够好好的多做做: #include<iostream> #include<string> #include<cstdio> #include<cstring> #include<queue> #include<map> #include<cmath> #include<stack> #include<set> #include<vector> #in…
Curling 2.0 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 30   Accepted Submission(s) : 16 Problem Description On Planet MM-21, after their Olympic games this year, curling is getting popular.…
POJ 2676 Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17627   Accepted: 8538   Special Judge Description Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the…
题目分析: 对于A,B,C,D四支队伍,两两之间进行一场比赛,获胜得3分,平局得1分,失败不得分,现在对给出的四个队伍的得分,判断能否满足得到这种分数,且方案唯一输出yes,不唯一输出no,不可能则输出worng,由于一共只有6场比赛,直接通过暴力每一种可能,创建mat[i][j]存放队伍i和队伍j比赛对于i来说的得分,mat[j][i]存放对于j来说的得分,然后建立cal(int row,int col)深搜函数,对于每个mat[row][col]的结果都进行递归,查询得分为3,1,0的三种情…
比较简单的一题 遍历左右的时候注意一下 #include<bits/stdc++.h> using namespace std; ; ]; ; vector<int>t; vector<int>p[N]; int n; void dfs(int v) { ){ ; ]!=-||s[i*+]!=-){ return; } p[cnt++]=t; return ; } t.push_back(s[v]); dfs(v*+); dfs(v*); t.pop_back(); }…
题目 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 guaranteed that a path exists for any request. I…
题目 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 between his/her starting city and the destinatio…
题目 A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. Input Each input file contains one test case. Each case starts with a line containing 0 < N < 100, the number of nodes in a t…
题干前半略. Sample Input 1: 8 98 72 86 60 65 12 23 50   Sample Output 1: 98 86 23 98 86 12 98 72 65 98 72 60 50 Max Heap   Sample Input 2: 8 8 38 25 58 52 82 70 60   Sample Output 2: 8 25 70 8 25 82 8 38 52 8 38 58 60 Min Heap   Sample Input 3: 8 10 28 15…
It 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 to keep the rest of…
树状数组+二分. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<stack> #include<vector> using namespace…
题目链接 解法暴力 因为有 0000, -0000 这样的数据,所以用字符串处理 同性的时候,遍历好朋友时会直接遍历到对方,这个时候应该continue #include<cstdio> #include<iostream> #include<cstring> #include<string> #include<vector> #include<algorithm> #include<unordered_map> #inc…
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 as its ID. Given any query from a reader, you are s…
题目 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 houses are in its service range. Now given the map…
题目 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 in 1, 10, 11, and 12. Input Specification: Each…
http://115.28.138.223:81/view.page?opid=5 这道题问的很怪. 起点DFS,每一个点还要DFS一次,统计不能到终点的个数 数据量不大这样做也能AC #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int x,y,ax,ay,bx,by;//'#'0, '+'1, '-'2, '|'…