
PAT甲级真题
文章平均质量分 52
Daimorpher
这个作者很懒,什么都没留下…
展开
-
1001. A+B Format (20)
#include#includeusing namespace std;int main(){ int a, b; cin >> a; cin.get(); cin >> b; cin.get(); int sum = a + b; if (sum < 0) { cout << "-"; sum = -sum; } if (sum < 1原创 2018-01-02 14:41:58 · 126 阅读 · 0 评论 -
1045. Favorite Color Stripe (30)(LISDP)
给Eva想要的颜色编序号,之后就转换为求最长非递减上升子序列长度#include<iostream>#include<algorithm>using namespace std;int n, m, l, num;const int maxn = 1e4 + 10;int a[maxn], b[maxn], dp[maxn], x;int main(){ in...原创 2018-02-28 20:29:26 · 292 阅读 · 0 评论 -
1074. Reversing Linked List (25)
这个题目很经典,有两个点,一个是地址给出来怎么连接到一起,另一个是每k个数翻转#include<iostream>#include<algorithm>using namespace std;const int maxn = 1e5 + 10;int w[maxn], nt[maxn],f[maxn];int s, n, k, x, cnt;int main()...原创 2018-03-02 11:27:07 · 211 阅读 · 0 评论 -
1079. Total Sales of Supply Chain (25)
bfs遍历一下就行double读入用lf才能读入,否则会出错#include<iostream>#include<algorithm>#include<vector>#include<queue>using namespace std;const int maxn = 1e5 + 10;vector<int>a[maxn];...原创 2018-03-05 15:51:25 · 135 阅读 · 0 评论 -
1095. Cars on Campus (30)
#include#include#include#includeusing namespace std;const int maxn = 1e4 + 10;int n, k;struct car { char num[10]; int hh, mm, ss; int flag; int intime, outtime; void read() { scanf("%s %d:原创 2018-03-12 20:08:05 · 134 阅读 · 0 评论 -
1084. Broken Keyboard (20)
two points应用#include#include#include#includeusing namespace std;string a, b;vectorss;int main(){ getline(cin, a); getline(cin, b); for (int i = 0; i = 'a'&&a[i] <= 'z')a[i] -= 32; for (i原创 2018-03-12 20:42:55 · 127 阅读 · 0 评论 -
1080. Graduate Admission (30)
二次更新正确答案#include<iostream>#include<algorithm>#include<vector>using namespace std;const int maxn = 1e5 + 10;struct point { int id, ge, gi, fg; int choice[5]; bool operator<...原创 2018-03-05 18:33:42 · 198 阅读 · 0 评论 -
1097. Deduplication on a Linked List (25)
好久没来更新了,之前买了晴神宝典,推荐给大家,专门针对PAT的书,非常管用,最近感觉进步还可以,思路清晰多了好了,然后这条题目,比较简单吧,静态链表,然后分割,我用了两个vector存的两个分割后的链表,map用来做已出现的数字的标记(记得取相反的),最后输出一下就好#include#include#includeusing namespace std;const int maxn原创 2018-03-22 19:53:26 · 184 阅读 · 0 评论 -
1099. Build A Binary Search Tree (30)
这个写的有点麻烦了,最后对应用的map其实中序遍历的时候边遍历边写入会简洁很多#include#include#include#include#includeusing namespace std;const int maxn = 1e3 + 10;int tree[maxn][2], n, s[maxn];vectorinorder, levelorder;mapm;原创 2018-03-26 22:50:24 · 140 阅读 · 0 评论 -
1080 Graduate Admission (30)(30 分)
emmm好久没来写过了,写了一个思路比较清晰的解法,仅供参考#include<iostream>#include<algorithm>#include<vector>using namespace std;const int maxn = 4e4 + 10;const int maxm = 110;const int maxk = 5;struct...原创 2018-06-19 23:41:15 · 375 阅读 · 0 评论 -
1022 Digital Library (30)(30 分)
要气疯了,,,最后发现是没写%07d,emmmm#include<iostream>#include<string>#include<algorithm>#include<vector>using namespace std;const int maxn = 1e4 + 10, maxnm = 1e3 + 10;struct boo...原创 2018-07-19 15:52:46 · 393 阅读 · 1 评论 -
1074 Reversing Linked List (25)(25 分)
#include<iostream>#include<algorithm>#include<vector>using namespace std;const int maxn = 1e5 + 10;struct Node { int add, data, next;}node[maxn];void init(){ for (int i =...原创 2018-07-25 22:46:28 · 910 阅读 · 1 评论 -
1102 Invert a Binary Tree(25 分)
静态树存储,找一下根节点,遍历的时候左右节点换一下就可以了算法笔记上给的方法是:后序遍历时交换左右子树,重建二叉树,再进行遍历#include<iostream>#include<cstring>#include<queue>#include<vector>using namespace std;int n;const int ...原创 2018-08-06 10:38:10 · 866 阅读 · 0 评论 -
1079 Total Sales of Supply Chain (25)(25 分)
DFS:递归终点为叶子结点,此时计算乘积#include<iostream>#include<queue>#include<vector>using namespace std;const int maxn = 1e5 + 10;struct node { double p, product; vector<int>child;...原创 2018-08-06 12:34:29 · 473 阅读 · 0 评论 -
1053 Path of Equal Weight (30)(30 分)
典型题目:静态树存储,DFS遍历#include<iostream>#include<vector>#include<algorithm>using namespace std;int n, m, s;const int maxn = 110;struct node { int weight; vector<int>child;...原创 2018-08-03 14:01:00 · 571 阅读 · 1 评论 -
1043 Is It a Binary Search Tree (25)(25 分)
模板题目:树的创建(插入节点,新建节点),树的遍历(前中后遍历都是DFS)#include<iostream>#include<vector>using namespace std;struct node { int data; node* lchild; node* rchild;};int num[10000], n;node* Newnode(...原创 2018-08-03 16:10:08 · 710 阅读 · 0 评论 -
1042 Shuffling Machine (20)(20 分)
#include<iostream>#include<string>#include<cstring>using namespace std;const int maxn = 1e3 + 10;int num[maxn], temp[maxn],shuff[maxn], k;void show(int n){ if (n <= 13)pr...原创 2018-08-22 11:49:38 · 253 阅读 · 0 评论 -
1046 Shortest Distance (20)(20 分)
#include<iostream>#include<algorithm>using namespace std;const int maxn = 1e5 + 10;int a[maxn], n;int main(){ scanf("%d", &n); int x, tot = 0; for (int i = 1; i <= n; i++)...原创 2018-08-22 12:01:28 · 221 阅读 · 0 评论 -
1066. Root of AVL Tree (25)
好久没写博客了,更新一波这个是课本上的东西,一模一样,就是树的形式变换要记一下,没那个示意图估计是写不出来了还有就是之前碰到二叉树建树的问题发现课本没有建二叉树的程序,其实就是这个题目,二叉树怎么都可以建出来,只是不一定是avl树(最坏是一条链)#include#includeusing namespace std;const int maxn = 21;int n, a[ma原创 2018-02-27 17:37:46 · 242 阅读 · 0 评论 -
1030. Travel Plan (30)
#include#includeconst int INF = 1e6;using namespace std;const int maxn = 5e2 + 10;int md[maxn][maxn], mc[maxn][maxn];int vis[maxn], dis[maxn], path[maxn], c[maxn];int n, m, s, d, c1, c2, dist,原创 2018-01-29 21:44:46 · 287 阅读 · 0 评论 -
1029. Median (25)
#include#include#includeusing namespace std;vectora;int n, m;long int x;int main(){ cin >> n; while (n--)cin >> x, a.push_back(x); cin >> m; while (m--)cin >> x, a.push_back(x); nth_eleme原创 2018-01-29 17:13:23 · 108 阅读 · 0 评论 -
1002. A+B for Polynomials (25)
#include#includeusing namespace std;typedef struct Node * List;struct Node { int expon; double coef; List Next;};void Attach(int expon, double coef, List * Rear){ List tmp = new struct Node原创 2018-01-02 15:31:02 · 112 阅读 · 0 评论 -
1003. Emergency (25)
#includeusing namespace std;const int INF = 1000000;const int MaxN=501;int N, M, S, T;int team[MaxN];int map[MaxN][MaxN];int path[MaxN];int amount[MaxN];int collected[MaxN];int dist[MaxN];原创 2018-01-03 17:39:11 · 135 阅读 · 0 评论 -
1004. Counting Leaves (30)
#includeusing namespace std;#include#includemap>adjlist; //每一个int对应一个数组索引int levelleaves[101];void dfs(int node, int level){ if (adjlist[node].empty()) //node那一行是不是空的,是空的,说明这层有叶节点,就加一 { lev原创 2018-01-03 20:02:26 · 100 阅读 · 0 评论 -
1005. Spell It Right (20)
终于碰到会做的了,,,这个真的简单#include#includeusing namespace std;void Print(char a){ char num[10]; switch (a) { case '0': cout << "zero"; break; case '1': cout << "one"; break; case '2'原创 2018-01-03 20:31:02 · 104 阅读 · 0 评论 -
1006. Sign In and Sign Out (25)
#include#includeusing namespace std;int main(){ int N; char IDin[16], IDout[16], In[9] = "23:59:59", Out[9] = "00:00:00"; char ID_number[16], Signintime[9], Signouttime[9]; cin >> N; while (原创 2018-01-03 21:57:16 · 151 阅读 · 0 评论 -
1007. Maximum Subsequence Sum (25)
#includeusing namespace std;int a[10000];int main(){ int N; cin >> N; for (int i = 0; i < N; i++) cin >> a[i]; int thislist = 0, maxlist = 0; int i; int front = 0, rear = 0, mf = 0, mr =原创 2018-01-04 15:38:13 · 120 阅读 · 0 评论 -
1008. Elevator (20)
#includeusing namespace std;const int uptime = 6;const int downtime = 4;const int staytime = 5;int main(){ int sumtime = 0; int N; cin >> N; int floor; cin >> floor; N = N - 1; sumtime +原创 2018-01-04 19:00:45 · 99 阅读 · 0 评论 -
1009. Product of Polynomials (25)
#include#includeusing namespace std;typedef struct Node * List;struct Node { int expon; double coef; List Next;};void Attach(int expon, double coef, List * Rear){ List tmp = new struct Node原创 2018-01-04 21:29:58 · 107 阅读 · 0 评论 -
1010. Radix (25)
#include#includeusing namespace std;long long Cal(char a){ if (a >= '0'&&a <= '9') return a - '0'; else return a - 'a' + 10;}long long NUM(char N[], long long radix){ long long sum = 0;原创 2018-01-05 08:34:53 · 178 阅读 · 0 评论 -
1011. World Cup Betting (20)
#includeusing namespace std;#includeint findmax(double team[]){ double max=0.0; int num; for (int i = 0; i < 3; i++) { if (team[i] > max) { max = team[i]; num = i; } } return num原创 2018-01-05 09:27:47 · 120 阅读 · 0 评论 -
1012. The Best Rank (25)
#include#include#include#includeusing namespace std;struct stu { int ID; int C; int M; int E; int A; int bestRank; char bestItem; stu(int id, int c, int m, int e) :ID(id), C(c), M(m), E(e原创 2018-01-06 15:26:57 · 170 阅读 · 0 评论 -
1013. Battle Over Cities (25)
#include#includeusing namespace std;const int MaxE = 1001;int edge[MaxE][MaxE];int visited[MaxE];int N, M, K;void dfs(int i){ visited[i] = 1; for (int j = 1; j <= N; j++) { if (!visited[j转载 2018-01-06 18:12:28 · 112 阅读 · 0 评论 -
1014. Waiting in Line (30)
果然最重要的还是读懂题目,,这个是动态的排队过程,黄线外面的人看那个队少了一个人就插进去,一开始想简单了,以为是大家都全部排好再开始,这个题目是黄线以内的排好后就开始,后面的人动态的插进去#includeusing namespace std;const int MaxN = 10001;int N, M, K, Q;int protime[MaxN]; typedef stru原创 2018-01-06 21:28:15 · 158 阅读 · 0 评论 -
1015. Reversible Primes (20)
#include#include#includeusing namespace std;bool isPrime(int N){ if (N < 2)return false; if (N == 2 || N == 3)return true; for (int i =sqrt(N); i >=2; i--) if (N%i == 0)return false; return原创 2018-01-06 23:05:33 · 135 阅读 · 0 评论 -
1016. Phone Bills (25)
#include#include#include#include#define daytime 24using namespace std;struct PhoneBills { char id[21]; bool on; int month; int dd, hh, mm;};void reaDln(PhoneBills * PB, int N)//这个真的厉害,oNof转载 2018-01-07 21:36:14 · 132 阅读 · 0 评论 -
1025. PAT Ranking (25)
#include#include#include#includeusing namespace std;const int maxn = 110;const int maxk = 310;int n, k;struct point { string rn; int score; int local_number; int local_rank; int final_ran原创 2018-01-28 16:02:32 · 106 阅读 · 0 评论