PAT甲练习
自信的小螺丝钉
这个作者很懒,什么都没留下…
展开
-
PAT 甲 1030 Travel Plan Dijkstra+DFS 算法
2022.2.13 练习 PAT 甲 1030 Travel Plan (原题链接)题解一:#include <bits/stdc++.h>using namespace std;const int MAX_NUM=510;const int INF=0x3fffffff;int n,m,s,D;int d[MAX_NUM];//起点到各点的最短路径长度int visit[MAX_NUM]={0};//标记是否已经访问int G[MAX_NUM][MAX_NUM];//邻接矩原创 2022-02-13 14:23:04 · 528 阅读 · 0 评论 -
PAT 甲 1003 Emergency Dijkstra算法
2022.2.13 练习 PAT 甲 1003 Emergency (原题链接)写错一个变量名,半天找不到错,我的母语是无语。注:本题是无向图情况#include <bits/stdc++.h>using namespace std;const int MAX_NUM=510;const int INF=0x3fffffff;int n,m,C1,C2;int weight[MAX_NUM];int w[MAX_NUM]={0};//从起点到u点收集到的最大物资int d[M原创 2022-02-13 03:02:28 · 359 阅读 · 0 评论 -
PAT 甲 1076 Forwards on Weibo 图的BFS
2022.2.12 练习 PAT甲 1076 Forwards on Weibo (原题链接)#include <bits/stdc++.h>using namespace std;const int MAX_NUM=1010;int inq[MAX_NUM]={0};struct Node{ int v; int layer;};vector<Node> adj[MAX_NUM];int BFS(int s,int l){ int原创 2022-02-12 19:20:24 · 169 阅读 · 0 评论 -
PAT 甲 1034 Head of a Gang
2022.2.11 练习 PAT甲 1034 Head of a Gang (原题链接)#include <bits/stdc++.h>using namespace std;const int MAX_NUM=2010;int n,k;int num=0;int G[MAX_NUM][MAX_NUM]={0};int weight[MAX_NUM]={0};int visit[MAX_NUM]={0};map<int,string> int_to_string原创 2022-02-11 21:48:51 · 288 阅读 · 0 评论 -
洛谷 P1433 吃奶酪 状态压缩DP
练习动态规划中本题参考博客:P1433 吃奶酪 (状压dp)洛谷 普及组 P1433 吃奶酪原题链接:洛谷 P1433 吃奶酪#include <bits/stdc++.h>using namespace std;double x[16],y[16],d[16][16],dp[16][40000];double dis(int a,int b){ return sqrt( (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b])原创 2022-02-11 15:15:30 · 341 阅读 · 0 评论 -
PAT 甲 1068 Find More Coins 还得看看哈
2022.2.10 练习 PAT 甲 1068 Find More Coins (原题链接)背包问题#include <bits/stdc++.h>using namespace std;int c[10010];int dp[10010]={0};int choice[10010][110];int flag[10010];bool cmp(int a,int b){ return a>b;}int main(){ std::ios::sync原创 2022-02-10 22:22:53 · 72 阅读 · 0 评论 -
PAT 甲 1040 Longest Symmetric String
2022.2.10 练习 PAT 甲 1040 Longest Symmetric String (原题链接)#include <bits/stdc++.h>using namespace std;char s[1010];int dp[1010][1010];int main(){ std::ios::sync_with_stdio(false); cin.getline(s,1010); int len=strlen(s); memset(dp,原创 2022-02-10 16:53:42 · 106 阅读 · 0 评论 -
PAT 甲 1045 Favorite Color Stripe
2022.2.10 练习 PAT 甲 1045 Favorite Color Stripe(原题链接)本题要注意当给出的序列中没有一个是Eva喜欢的颜色的情况,以及跳过序列中Eva不喜欢的颜色#include <bits/stdc++.h>using namespace std;int c[210];int a[10010];int dp[10010];int main(){ std::ios::sync_with_stdio(false); int n;原创 2022-02-10 16:00:15 · 251 阅读 · 0 评论 -
PAT 甲 1007 Maximum Subsequence Sum
2022.2.10 练习 PAT 甲 1007 Maximum Subsequence Sum (原题链接)#include <bits/stdc++.h>using namespace std;int a[10010];int dp[10010];int main(){ std::ios::sync_with_stdio(false); int n; cin>>n; int num=0; for(int i=0;i<n;i原创 2022-02-10 14:58:09 · 81 阅读 · 0 评论 -
PAT 甲 1107 Social Clusters
2022.1.29 练习 PAT 甲 1107 Social Clusters (原题链接)并查集,好吧其实我没那么懂,算法笔记上的解法nb,再次反思自己的不开窍。题解如下:#include <bits/stdc++.h>using namespace std;const int MAX_SIZE=1010;int father[MAX_SIZE];int isroot[MAX_SIZE]={0};//记录每个结点是否作为某个集合的根结点int course[MAX_SIZE]原创 2022-01-29 16:45:23 · 651 阅读 · 0 评论 -
PAT 甲 1066 Root of AVL Tree
2022.1.29 练习 PAT 甲 1066 Root of AVL Tree (原题链接)建立一颗平衡二叉树(代码参考算法笔记对应内容)题解如下:#include <bits/stdc++.h>using namespace std;int n;int d[22];struct node{ int data; int height; node* lchild; node* rchild;};int getHeight(node* ro原创 2022-01-29 14:56:42 · 710 阅读 · 0 评论 -
PAT 甲 1099 Build A Binary Search Tree
2022.1.28 练习 PAT甲 1099 Build A Binary Search Tree (原题链接)题解如下:#include <bits/stdc++.h>using namespace std;const int MAX_SIZE=110;int n;int indexx=0;int num[MAX_SIZE];struct node{ int data; int lchild; int rchild;}Node[MAX_SIZE];原创 2022-01-29 02:44:09 · 809 阅读 · 0 评论 -
妙啊 PAT 甲 1064 Complete Binary Search Tree
2022.1.28 练习 PAT甲 1064 Complete Binary Search Tree (原题链接)妙啊,自己想的好麻烦,一看算法笔记上的题解,佩服佩服,我的脑袋怎么这么不转弯。。。思想:步骤1: 如果使用数组来存放完全二叉树,那么对完全二叉树当中的任何一个结点(设编号为x,其根结点编号为1),其左孩子结点的编号为2x,右孩子结点的编号为2x+1。那么就可以开一个数组CBT[MAX_SIZE],其中CBT[1]~CBT[n]按层序存放完全二叉树的n个结点。步骤2: 考虑到对一颗二叉排原创 2022-01-29 02:17:47 · 909 阅读 · 0 评论 -
PAT 甲 1004 Counting Leaves
2022.1.28 练习 PAT甲 1004 Counting Leaves (原题链接)题解如下:#include <bits/stdc++.h>using namespace std;const int MAX_SIZE=110;int num[MAX_SIZE]={0};vector<int> Node[MAX_SIZE];int max_high=0;void DFS(int index,int high){ if(Node[index].s原创 2022-01-28 23:51:23 · 72 阅读 · 0 评论 -
PAT 甲 1079 Total Sales of Supply Chain
2022.1.28 练习 PAT甲 1079 Total Sales of Supply Chain (原题链接)题解如下:#include <bits/stdc++.h>using namespace std;const int MAX_SIZE=100010;int n;double p,r;struct node{ int data; vector<int> child;}Node[MAX_SIZE];double sum=0;voi原创 2022-01-28 23:34:20 · 98 阅读 · 0 评论 -
PAT 甲 1106 Lowest Price in Supply Chain
2022.1.28 练习 PAT甲 1106 Lowest Price in Supply Chain(原题链接)题解如下:#include <bits/stdc++.h>using namespace std;const int MAX_SIZE=100010;const int INF=1e8;int n;double p,r;vector<int> child[MAX_SIZE];int min_high=INF,num=0;void DFS(int原创 2022-01-28 23:22:21 · 87 阅读 · 0 评论 -
PAT 甲 1090 Highest Price in Supply Chain
2022.1.28 练习 PAT甲 1090 Highest Price in Supply Chain (原题链接)段错误代码:(不明白为什么段错误,呜呜,求大佬指正)#include <bits/stdc++.h>using namespace std;const int MAX_SIZE=100010;int n;double p,r;int hashtable[MAX_SIZE]={0};struct node{ vector<int> child原创 2022-01-28 22:18:55 · 317 阅读 · 0 评论 -
PAT 甲 1102 Invert a Binary Tree
2022.1.28 练习 PAT甲 1102 Invert a Binary Tree(原题链接)反转二叉树:进行后序遍历,在后序遍历访问根节点时交换左孩子和右孩子。题解如下(使用静态树):#include <bits/stdc++.h>using namespace std;int n;struct node{ int data; int lchild; int rchild; int flag;}Node[12];vector<in原创 2022-01-28 19:22:17 · 76 阅读 · 0 评论 -
PAT 甲 1086 Tree Traversals Again
2022.1.28 练习 PAT甲 1086 Tree Traversals Again (原题链接)已知先序和中序遍历,求后序遍历题解如下:#include <bits/stdc++.h>using namespace std;int n;struct node{ int data; node* lchild; node* rchild;};stack<int> inorder;vector<int> pre;vecto原创 2022-01-28 18:08:28 · 276 阅读 · 0 评论 -
PAT 甲 1094 The Largest Generation(有点问题)
2022.1.28 练习 PAT甲 1094 The Largest Generation(原题链接)自己写的代码(19分),暂时想不通为何扣分,记录留待以后思考。#include <bits/stdc++.h>using namespace std;const int MAX_SIZE=110;int n,m;int a[MAX_SIZE]={0};struct node{ int parent; int level;}Node[MAX_SIZE];in原创 2022-01-28 16:14:25 · 193 阅读 · 0 评论 -
PAT 甲 1043 Is It a Binary Search Tree
2022.1.23 练习 PAT甲 1043 Is It a Binary Search Tree(原题链接)每次复制一段代码到其他地方,都不记得把该改的都改完了,你不0分谁0分,我对自己呵呵两声。。。。题解如下:#include <bits/stdc++.h>using namespace std;int n;vector<int> input;vector<int> pre;vector<int> post;vector<in原创 2022-01-27 23:46:38 · 360 阅读 · 0 评论 -
PAT 甲 1020 Tree Traversals
2022.1.23 练习 PAT甲 1020 Tree Traversals (原题链接)已知一个非空二叉树的中序遍历和后序遍历,求输出层序遍历。题解如下:#include <bits/stdc++.h>using namespace std;const int MAX_SIZE=30;int post[MAX_SIZE];//后序int in[MAX_SIZE];//中序int n;struct node{ int data; node* lchild;原创 2022-01-23 22:33:41 · 323 阅读 · 0 评论 -
PAT 甲 1052 Linked List Sorting 踩坑链表题
2022.1.22 练习 PAT甲 1052 Linked List Sorting (原题链接)坑点已在代码相应位置添加注释心得:链表题注意测试点中可能含有无效结点,需要遍历构造链表,排除无效结点,构造出一条有效的链表。题解如下:#include<bits/stdc++.h>using namespace std;const int MAX_SIZE=1e6+5;struct Node{ int address; int data; int next;原创 2022-01-23 01:52:40 · 140 阅读 · 0 评论 -
PAT 甲 1032 Sharing
2022.1.22 练习 PAT甲 1032 Sharing(原题链接)题解如下:#include<bits/stdc++.h>using namespace std;const int MAX_SIZE=1e6+5;struct Node{ string data; int next; int flag;}node[MAX_SIZE];int main(){ std::ios::sync_with_stdio(false); int原创 2022-01-22 23:30:13 · 168 阅读 · 0 评论 -
PAT 甲 1065 A+B and C (64bit)(学习)
2022.1.2练习 PAT 甲 1065 A+B and C(原题链接)大佬的题解分析转载 2022-01-03 11:11:04 · 52 阅读 · 0 评论 -
PAT 甲 1046 Shortest Distance
2022.1.2练习 PAT甲 1046 Shortest Distance(原题链接)渣渣题解如下:#include<bits/stdc++.h>using namespace std;const int MAX_NUM=1e5+5;int d[MAX_NUM];int main(){ std::ios::sync_with_stdio(false); int N; cin>>N; int sum=0; d[0]=0;原创 2022-01-02 18:59:45 · 318 阅读 · 0 评论 -
PAT 甲 1042 Shuffling Machine
2021.12.31练习 PAT甲 1042 Shuffling Machine渣渣题解如下:#include<bits/stdc++.h>using namespace std;int c[55];struct Node{ int num; int next;}a[55];int cmp(Node a,Node b){ return a.next<b.next;}int main(){ std::ios::sync_with_st原创 2021-12-31 17:07:00 · 448 阅读 · 0 评论