![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
PTA
伊拉克857
小菜鸡一枚
展开
-
L2-020 功夫传人
题目:https://pintia.cn/problem-sets/994805046380707840/problems/994805059118809088第一次用堆栈处理的(好麻烦,还是菜)#include<iostream>#include<queue>#include<vector>using namespace std;int main(){ int n,k; double z,r,sum = 0.0; scanf("%d %lf %.原创 2022-04-09 12:58:35 · 211 阅读 · 0 评论 -
L2-019 悄悄关注
题目:https://pintia.cn/problem-sets/994805046380707840/problems/994805059731177472题目简单但想用STL (但不熟练查半天资料)#include<iostream>#include<map>using namespace std;map<string,int> cnt;//用map存所有用户,已关注的设-1,如果点赞列表有关注的用户则不变。 int main(){ int n,原创 2022-04-08 10:59:48 · 202 阅读 · 0 评论 -
L2-012 关于堆的判断
题目:https://pintia.cn/problem-sets/994805046380707840/problems/994805064676261888堆的应用:(注意处理4个条件)#include<iostream>#include<vector>using namespace std;int n;vector<int> v; //记录堆 void updata(int i){ // 更新堆,生成小堆顶 if(i == 1) return原创 2022-04-01 11:32:04 · 54 阅读 · 0 评论 -
L2-011 玩转二叉树
题目:https://pintia.cn/problem-sets/994805046380707840/problems/994805065406070784思路:已知前序中序,与求后序一致,新增形参index,记录位置,题目要求反转,(开始的节点从1开始)左子树 为index*2+1,右子树为index*2.(如果开始的节点为0)左子树为index*2+2,右子树为index*2+1. (注意记录层状的空间要大,最后的测试点可能为一侧子树(一边倾)导致数字过大)#include<iost原创 2022-03-31 11:03:09 · 1231 阅读 · 0 评论 -
L2-007 家庭房产
题目:https://pintia.cn/problem-sets/994805046380707840/problems/994805068539215872并查集的复习:int father[10000];//一个大的集合//开始前初始化//设1每个节点的父节点都是自己//2或者都设为-1 //查找,返回节点的祖宗 int find(int x){ whlie(x != father[x]){ x = fatehr[x]; } return x;}//把a,b的祖宗原创 2022-03-27 15:49:35 · 252 阅读 · 0 评论 -
L2-006 树的遍历
首先回顾一下已知后续和中序求前序:#include <iostream>using namespace std;int post[] = {3, 4, 2, 6, 5, 1};int in[] = {3, 2, 4, 1, 6, 5};void pre(int root, int start, int end) { if(start > end) return ; int i = start; while(i < end && i原创 2022-03-26 11:17:37 · 1273 阅读 · 0 评论 -
L2-005
题目:https://pintia.cn/problem-sets/994805046380707840/problems/994805070149828608该代码最后测试点超时(应该是数据较多频繁调用set导致)#include<iostream>#include<vector>#include<set>using namespace std;int main(){ int n,k,m,temp,a,b; scanf("%d",&n);原创 2022-03-25 15:33:40 · 61 阅读 · 0 评论 -
L2-004 这是二叉搜索树吗?
题目:https://pintia.cn/problem-sets/994805046380707840/problems/994805070971912192首先是建树做法(没有去添加镜像,导致有两个点没过)#include<iostream>#include<vector>using namespace std;vector<int> v,pre;int n;bool f = false;//建树 typedef struct TNode原创 2022-03-24 14:33:18 · 149 阅读 · 0 评论 -
L2 - 001
Dijkstra算法适用于边权为正的情况,用于计算正权图的单源最短路,即从单个源点出发,到所有节点的最短路。同时适用于有向图和无向图。模板://处理图....begin为起点 int n,begin; int chart[][],path[];//chart为图 path[i]为起点到i的距离 bool visit[]; //是否被访问 //初始化 起点为path为0 memset(visit,0,sizeof(visit)); for(int i = 0;i <原创 2022-03-23 09:05:26 · 88 阅读 · 0 评论 -
L2-002 链表去重
先浅浅记录一下:#include<iostream>#include <cmath>using namespace std;int Key[100005],Next[100005],Out[100005],Next2[100005];bool Judge[100005];int main() { int begin,n; cin >> begin >> n; int a,b,c; for(int i = 0;i < n;i+原创 2022-03-22 18:30:36 · 1544 阅读 · 0 评论