
PAT
文章平均质量分 52
tcmyxc
在这个国度中,必须不停地奔跑,才能使你保持在原地。——红皇后假说
展开
-
PAT1146 Topological Order
思路因为对拓扑排序来说,每个可以选择的点的入度都为0,这里只是判断是否是拓扑排序,因此我们可以判断序列中的每个顶点入度是否为0来解决,如果不为0,则不是拓扑排序。代码#include <iostream>#include <vector>using namespace std;vector<int> adj[1005], path(1005), f, inDegree(1005), myDegree(1005);int main(){ int n, m;原创 2021-03-17 11:02:54 · 107 阅读 · 0 评论 -
PAT1150 Travelling Salesman Problem
文章目录题目代码题目The “travelling salesman problem” asks the following question: “Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city and returns to the origin city?” It is an NP-hard pr原创 2021-03-15 20:00:44 · 121 阅读 · 0 评论 -
PAT1004 Counting Leaves
文章目录题目思路代码题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805521431773184思路DFS代码#include <iostream>#include <vector>using namespace std;vector<int> in[105];int cnt[105] = {0};int maxLevel = 1;//最大层数 void dfs原创 2021-03-12 14:05:57 · 74 阅读 · 0 评论 -
PAT1151
文章目录题目思路代码参考文献题目The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants.Given any two nodes in a binary tree, you are supposed to find their LCA.Input Specification:Each input file conta原创 2021-03-04 22:25:13 · 158 阅读 · 1 评论 -
PAT1155
文章目录思路代码参考文献思路回溯代码版本一:#include <iostream>#include <vector>using namespace std;//const int INF = 1e7;const int MAXN = 1005;int in[MAXN];vector<vector<int> > res;void backtrace(int parent, int n, vector<int> &pat原创 2021-03-04 20:30:01 · 678 阅读 · 1 评论 -
PAT1154
文章目录思路:DFS柳神代码:参考文献思路:DFS柳神写的代码让我自惭形秽,我是个菜鸡#include <iostream>#include <vector>#include <set>using namespace std;const int maxn = 10005;vector<int> color(maxn);vector<int> v[maxn];bool visited[maxn] = {false};//int原创 2021-03-03 21:09:44 · 89 阅读 · 1 评论 -
PAT1108
题目链接思路参考柳神,使用sscanf和sprintf,引用下面评论的话就是sscanf和sprintf用的太妙了。当sscanf读入的字符串没有与之匹配的类型的时候,temp的值会是浮点数的0,这样在sprintf将0写到字符数组b后,和字符数组a相比较就会不同。轻松解决了判断是否含有非数字,有几个小数点等,计算小数部分和整数部分的问题来源:评论网友iczfy585代码#include <iostream>#include <cstdio>#include &l原创 2020-08-31 19:31:10 · 109 阅读 · 0 评论 -
PAT1107
题目题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805361586847744思路首先请把题目读懂,读不懂就多读几次,或者看看别人的题解。如果画图的话,一眼就能看出结果。但是将画图的思路转换成代码,那么考的就是并查集。并查集,简单合并,但是如果按照维斯的数据结构生搬硬套不行,也就是父指针数组初始化为-1在这里不行。推荐柳神的初始化策略,每个数字的父指针都初始化为本身。但是集合的大小就需要另外编程,这时候原创 2020-08-31 00:11:41 · 146 阅读 · 0 评论 -
PAT1106
题目题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805362341822464思路思路其实就是DFS,找最短的路径即可。其实大家可能会可能对输入有疑问,不知道输入是在说什么。这里的意思其实是给了图的邻接表表示法,第一行代表和编号0邻接的节点有编号为2、3、5的节点。更进一步,你可以认为只是个有向图,示意如下:代码#include <iostream>#include <vec原创 2020-08-29 20:46:46 · 113 阅读 · 0 评论 -
PAT1105
题目思路其实题目并不难,难点在于如何把数据存进去,关于数据的存储,我并不推荐柳神的方法(可能是我太菜了,感觉那样好麻烦),我更习惯于设置上、下、左、右的边界,这样好理解,也不方便出错代码#include <iostream>#include <cmath>#include <vector>#include <algorithm>using namespace std;bool cmp(int a, int b){ return a原创 2020-08-26 20:54:15 · 104 阅读 · 0 评论 -
PAT1104
题目思路参考柳神的代码代码#include <bits/stdc++.h>using namespace std;int main(){ int n; long long sum = 0; cin >> n; for(int i=1; i<=n; i++){ double tmp; cin >> tmp; sum = sum + (long long)(1000* tmp转载 2020-08-25 20:51:17 · 144 阅读 · 0 评论 -
PAT1101
题目题目来源:https://pintia.cn/problem-sets/994805342720868352/problems/994805366343188480思路其实很简单,如果我是主元,则前面最大的数要小于我,后面最小的要大于我,代码#include <iostream>#include <vector>using namespace std;int a[100005] = {0};int maxArr[100005] = {0};int mi原创 2020-08-25 20:45:23 · 131 阅读 · 0 评论 -
PAT1025
PAT1025题目描述思路代码错误点题目描述题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805474338127872思路参考算法笔记,自定义比较函数计算排名的思路很有意思int finRank = 1; for(int i=0; i<sum; i++){ if(st[i].score < st[i-1].score){ finRank = i+1; } st[i].翻译 2020-08-19 21:27:11 · 98 阅读 · 0 评论 -
PAT1008
文章目录题目描述思路代码题目描述题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805511923286016思路记录当前请求和上一次请求当前>上一次 => 上升当前<上一次 => 下降代码#include <iostream>using namespace std;int main(){ int n, pre=0, cur, sum=0;原创 2020-08-16 20:57:26 · 85 阅读 · 0 评论 -
PAT1006
文章目录问题描述代码说明问题描述题目来源:https://pintia.cn/problem-sets/994805342720868352/problems/994805516654460928代码#include <cstdio>#include <cstring>int max[3] = {0, 0, 0};int min[3] = {23, 59, 59};int main(){ int n, hms1[3], hms2[3]; ch原创 2020-08-05 22:41:45 · 94 阅读 · 0 评论 -
PAT1002
文章目录题目描述代码自己的错误点:题目描述题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805526272000000代码#include <stdio.h>void initPrintf(int k, double array[]);int main(){ double a[1001] = {0}; double b[1001] = {0}; double res原创 2020-07-31 22:47:52 · 132 阅读 · 1 评论