PTA
PTA题解
CyIce
啦啦啦啦
展开
-
1046 Shortest Distance
// // Created by CyIce on 2021/2/25. // #include <stdio.h> #include <algorithm> using namespace std; const int MAXN = 100010; // 记录节点1到节点i的距离,固定一个方向 int dis[MAXN] = {0}; int total = 0; int distance(int a, int b) { if (a > b) swap(a,原创 2021-02-25 16:05:33 · 89 阅读 · 1 评论 -
1042 Shuffling Machine
// // Created by CyIce on 2021/2/25. // #include <stdio.h> #include <algorithm> using namespace std; struct poker { char type; int num; int order; } pokers[54]p; int order[54]; void printPoker(poker p) { printf("%c%d", p.ty原创 2021-02-25 10:41:34 · 78 阅读 · 0 评论 -
1001 A+B Format
// // Created by CyIce on 2021/2/25. // #include <stdio.h> #include <stack> using namespace std; stack<int> S; void toString(int n) { int temp = n < 0 ? -n : n; if (n == 0) S.push(0); while (temp > 0) { S.pus原创 2021-02-25 10:14:45 · 86 阅读 · 0 评论 -
1057 Stack
分析 由于题目规定每个元素为105以内的正整数,所以可以使用分块的思想储存数据 // // Created by CyIce on 2021/2/24. // #include <stdio.h> #include <stack> #include <algorithm> #include <cstring> using namespace std; const int MAXN = 100010; const int SQRTN = 316; int原创 2021-02-24 14:58:22 · 75 阅读 · 0 评论 -
1030 Travel Plan C++
#include <stdio.h> #include <algorithm> #include <queue> using namespace std; const int MAXV = 510; int Distance[MAXV][MAXV], Cost[MAXV][MAXV]; int N, S, D, INF = 0x3fffffff, cost[MAXV], d[MAXV]; int pre[MAXV]; queue<int> q; bool原创 2021-01-20 12:09:20 · 178 阅读 · 0 评论 -
1003 Emergency C++
1003 Emergency C++ 分析 使用Dijkstra算法即可 代码 #include <stdio.h> #include <algorithm> using namespace std; const int MAXV = 510; const int INF = 0x3fffffff; //Team:每个城市的救援队数量 int n, G[MAXV][MAXV], Team[MAXV], pathNum = 0, teamNum = 0; // d[i]:起点到i原创 2021-01-19 14:38:28 · 175 阅读 · 0 评论 -
1043 Is It a Binary Search Tree C++
分析 以二叉排序树的前序序列为输入序列,重新构成的二叉排序树和原二叉排序树相同,因此,判断输入序列的是否是某一颗二叉排序树的前序序列,只需要判断用输入序列构成的二叉排序树的前序序列是否和输入序列相同即可。 // // Created by CyIce on 2021/1/12. // #include <stdio.h> #include <vector> using namespace std; const int MAXN = 1000; int N, inputList[M原创 2021-01-18 10:20:29 · 91 阅读 · 0 评论 -
1076 Forwards on Weibo (30分) C++
比较直接的一道题,注意存储数组G时要反向存储即可。 #include <stdio.h> #include <queue> using namespace std; //储存节点和当前层数信息 struct node { int v, layout; }; const int MAXN = 1010; int N, L, G[MAXN][MAXN] = {0}; int BFS(node Node) { int ans = 0; queue<no原创 2021-01-18 09:58:02 · 49 阅读 · 0 评论