编程练习
Ike_Lin
这个作者很懒,什么都没留下…
展开
-
1042 Shuffling Machine (20分)
#include<cstdio>#include<vector>#include<string>#include<iostream>#include<queue>#include<unordered_map>#include<algorithm>#define maxn 55using na...原创 2020-04-20 17:24:39 · 154 阅读 · 0 评论 -
1041 Be Unique (20分)
用数组记录更好,我这是为了练习unordered_map#include<cstdio>#include<vector>#include<string>#include<iostream>#include<queue>#include<unordered_map>#include<algorithm&g...原创 2020-04-20 17:01:43 · 159 阅读 · 0 评论 -
1040 Longest Symmetric String (25分)
当没有对称的字符串的时候,对称的字符串数为1,否则一个样例出错。#include<cstdio>#include<vector>#include<string>#include<iostream>#include<queue>#include<set>#include<algorithm>#de...原创 2020-04-20 16:45:42 · 169 阅读 · 0 评论 -
1039 Course List for Student (25分)
用map会导致最后一个样例超时,改为unordered_map通过,详细建议参考https://blog.csdn.net/weixin_41256413/article/details/83720314#include<algorithm>#include<string>#include<iostream>#include<vector>...原创 2020-04-20 16:33:29 · 811 阅读 · 0 评论 -
1038 Recover the Smallest Number (30分)
这道题的样例2比较坑,样例2是所有输入的数都为0,这个特例需要特殊判断,否则可能导致该样例的处理没有输出,导致错误。#include<cstdio>#include<vector>#include<string>#include<iostream>#include<queue>#include<set>#in...原创 2020-04-20 13:35:54 · 234 阅读 · 0 评论 -
1037 Magic Coupon (25分)
#include<cstdio>#include<vector>#include<string>#include<iostream>#include<queue>#include<set>#include<algorithm>#define maxn 22typedef long long ...原创 2020-04-20 12:34:59 · 183 阅读 · 0 评论 -
1036 Boys vs Girls (25分)
#include<cstdio>#include<vector>#include<string>#include<iostream>#include<queue>#include<set>#include<algorithm>#define maxn 22using namespace st...原创 2020-04-20 12:18:15 · 138 阅读 · 0 评论 -
1035 Password (20分)
#include<cstdio>#include<vector>#include<string>#include<iostream>#include<queue>#include<set>#include<algorithm>#define maxn 22using namespace st...原创 2020-04-20 12:00:05 · 216 阅读 · 0 评论 -
1030 Travel Plan (30分)PAT
典型的dijk+dfs能解的问题。#include<cstdio>#include<algorithm>#include<string>#include<vector>#include<iostream>#define maxn 5050#define inf 10001000using namespace std;...原创 2020-04-19 17:03:29 · 152 阅读 · 0 评论 -
1029 Median (25分)
送分题#include<cstdio>#include<algorithm>#include<string>#include<vector>#include<iostream>#define maxn 1001000using namespace std;vector<long long> v;int...原创 2020-04-19 12:30:16 · 143 阅读 · 0 评论 -
1028 List Sorting (25分)
说是N取10万内,但是maxn取100100仍然最后一个样例超时,后面加一个0就解决了。#include<cstdio>#include<algorithm>#include<string>#include<iostream>#define maxn 1001000using namespace std;struct node ...原创 2020-04-19 12:17:51 · 124 阅读 · 0 评论 -
1027 Colors in Mars (20分)
#include<cstdio>#include<algorithm>#include<string>#include<iostream>#define code1 13#define code2 10using namespace std;string toMars(int sum) { string out; ...原创 2020-04-19 12:00:21 · 140 阅读 · 0 评论 -
1025 PAT Ranking (25分)
注意最后输出注册号的时候需要用%013lld的方式输出,否则将导致最后一个样例答案错误。#include<cstdio>#include<algorithm>#include<cstdlib>struct student { long long reg_num; int score; int rank; int lo...原创 2020-04-19 10:04:08 · 269 阅读 · 0 评论 -
1024 Palindromic Number (25分) PAT
注意做变换之前检查一遍输入的数是否已经符合要求了。注意单位数的都是符合要求的。#include<cstdio>#include<vector>#include<string>#include<iostream>#include<queue>#include<set>#include<algorith...原创 2020-04-18 21:28:40 · 147 阅读 · 0 评论 -
1023 Have Fun with Numbers (20分)
#include<cstdio>#include<vector>#include<string>#include<iostream>#include<queue>#include<set>#include<algorithm>#define maxn 22using namespace st...原创 2020-04-18 20:27:08 · 140 阅读 · 0 评论 -
1022 Digital Library (30分)
#include<iostream>#include<string>#include<cstdio>#include<algorithm>#include<vector>#define maxn 10001000using namespace std;struct node { int id; st...原创 2020-04-18 19:50:05 · 120 阅读 · 0 评论 -
1021 Deepest Root (25分)
#include<cstdio>#include<vector>#include<string>#include<iostream>#include<queue>#include<set>#include<algorithm>#define maxn 10010using namespace...原创 2020-04-18 19:49:28 · 114 阅读 · 0 评论 -
1019 General Palindromic Number (20分)
#include<cstdio>#include<vector>#include<string>#include<iostream>#include<queue>#include<algorithm>#define maxn 101using namespace std;bool checkv(vec...原创 2020-04-18 19:48:38 · 137 阅读 · 0 评论 -
1085 Perfect Sequence (25分) PAT
一点小技巧降低计算复杂度,每次搜寻序列允许的最大值的时候,从上次的位置开始搜寻,这样可以将整个过程搜索序列允许最大值的复杂度降到O(N),其中N为输入序列的长度。另外,需要用long long否则最后一个样例出错。#include<cstdio>#include<vector>#include<string>#include<iostrea...原创 2020-04-18 19:47:47 · 137 阅读 · 0 评论 -
PAT(甲级)2019年冬季考试 7-1 Good in C (20分) 7-2 Block Reversing (25分) 7-3 Summit (25分) 7-4 Cartesian Tree (
7-1Good in C(20分)读题比较麻烦,实际不难,注意输出格式就可以了。#include<cstdio>#include<vector>#include<iostream>#include<queue>#include<cmath>#include<string>#include<alg...原创 2020-04-11 16:09:47 · 310 阅读 · 0 评论 -
1015 Reversible Primes (20分)
某个数是某个系统d的reversible primes需要满足,这个数本身是素数,且这个数转换成d进制后倒转过来再转化成10进制后的数仍然是素数。题意难懂但懂了就好做。下面的代码的巧妙之处在于reverse_with_radix取得的余数的顺序就刚好是换成d进制后倒转得到的顺序。需要注意的点:0和1不是素数。#include<cstdio>bool isprime...原创 2020-04-10 09:17:28 · 243 阅读 · 0 评论 -
1086 Tree Traversals Again (25分)
重点在于,结合栈来看,实现的是中序遍历,抛开栈,单看这些数字的顺序,则是前序遍历的结果,因此可以直接用前序中序转后序算法。#include<cstdio>#include<iostream>#include<vector>#include<string>#include<cmath>#include<stack>...原创 2020-04-09 21:17:55 · 119 阅读 · 0 评论 -
1097 Deduplication on a Linked List (25分) 段错误
其中一个样例段错误,找不出原因。#include<cstdio>#include<vector>#include<string>#include<cmath>#define maxn 100100#define maxm 10100using namespace std;vector<int> keep, remv;...原创 2020-04-09 18:07:57 · 320 阅读 · 1 评论 -
1100 Mars Numbers (20分)
#include<vector>#include<algorithm>#include<iostream>#include<string>#include<cstdio>#define maxn 13using namespace std;string one[maxn] = {"tret", "jan", "fe...原创 2020-04-09 17:05:13 · 123 阅读 · 0 评论 -
1104 Sum of Number Segments (20分)
第一个代码是对的,第二个代码不知道为什么会出现两个样例出错,而且不知道原因是什么。#include<cstdio>#include<vector>#include<algorithm>#include<cmath>#define maxn 1001000using namespace std;double num[maxn];i...原创 2020-04-08 21:34:04 · 145 阅读 · 0 评论 -
1105 Spiral Matrix (25分) PAT
核心部分参考了柳神的代码,需要重做。薄弱项#include<cstdio>#include<vector>#include<algorithm>#include<cmath>#define maxn 505#define inf 1000000000using namespace std;vector<int> num...原创 2020-04-08 18:58:24 · 170 阅读 · 0 评论 -
1111 Online Map (30分)
#include<cstdio>#include<vector>#define maxn 505#define inf 1000000000using namespace std;struct edge { int node, length, time; edge() {} edge(int n, int l, int t) : ...原创 2020-04-08 12:31:45 · 142 阅读 · 0 评论 -
1114 Family Property (25分)
#include<cstdio>#include<vector>#include<queue>#include<set>#include<vector>#include<algorithm>#define maxn 10100using namespace std;set<int> g[m...原创 2020-04-07 17:45:12 · 125 阅读 · 0 评论 -
1115 Counting Nodes in a BST (30分)
#include<cstdio>#include<vector>#include<queue>#define maxn 1010using namespace std;int c[maxn];struct node { int d, level; node *left, *right;};void inser(nod...原创 2020-04-07 16:57:11 · 112 阅读 · 0 评论 -
1119 Pre- and Post-order Traversals (30分) 重新做一次,理论基础不行
先根遍历和后根遍历无法确定一棵树的原因是,当某个结点只有一个子结点(或子树)时,无法确定其是左边的还是右边的。每当出现某个结点只有一个子结点或子树时,就无法确定一棵树。 建树后输出另一种遍历序列,并不一定要将这棵树建起来,根据遍历方式将结点插入vector就可以得到遍历序列。#include<cstdio>#include<vector>#define maxn ...原创 2020-04-07 12:16:42 · 237 阅读 · 0 评论 -
1125 Chain the Ropes (25分)
看懂题目就太简单了,但是看不懂题目就完蛋了,这个题目太难理解了。#include<cstdio>#include<vector>#include<queue>#include<algorithm>#define maxn 10100using namespace std;int main() { int N; in...原创 2020-04-07 08:28:38 · 102 阅读 · 0 评论 -
1126 Eulerian Path (25分)
水题。但是需要注意题目中的隐含条件,如图所示,要求是连通图,因此需要先判断是否是连通图,否则其中一个样例出错。#include<cstdio>#include<vector>#include<queue>#define maxn 550using namespace std;vector<int> g[maxn];int ...原创 2020-04-07 08:13:32 · 142 阅读 · 0 评论 -
1127 ZigZagging on a Tree (30分)PAT
根据前序和后序序列建树,建树时顺便记录层次。深度优先遍历树,单数层直接将node压入vector,双数层的结点压入栈中,等到单数层或者深度遍历结束后再压入vector。此处注意,深度优先遍历后应当检查栈中是否有结点,有应当压入vector。#include<cstdio>#include<stack>#include<queue>#inclu...原创 2020-04-06 21:35:41 · 216 阅读 · 0 评论 -
1130 (25分) PAT
#include<cstdio>#include<algorithm>#include<vector>#include<string>#include<iostream>#define maxn 22using namespace std;struct node { string data; int...原创 2020-04-06 20:18:05 · 100 阅读 · 0 评论 -
1052 Linked List Sorting (25分)
静态链表的题需要考虑有些输入的结点是不在由头结点引出的链表中的,因此需要注意输出的结点的数目可能跟输入的结点数不一致。#include<cstdio>#include<iostream>#include<string>#include<map>#include<algorithm>#define M 100100usi...原创 2020-04-06 18:59:01 · 138 阅读 · 0 评论 -
1133 Splitting A Linked List (25分)
静态链表的题需要考虑有些输入的结点是不在由头结点引出的链表中的,因此需要注意输出的结点的数目可能跟输入的结点数不一致。如代码中注释的地方,修改将导致部分样例出错。#include<cstdio>#include<algorithm>#include<vector>#define maxn 1001000using namespace std;s...原创 2020-04-06 18:57:41 · 122 阅读 · 0 评论 -
1135 Is It A Red-Black Tree (30分) PAT
#include<cstdio>#include<vector>#define maxn 33#define inf 300using namespace std;struct simplenode { int d; bool red; simplenode(int _d, bool _red):d(_d), red(_red) ...原创 2020-04-06 10:53:59 · 232 阅读 · 0 评论 -
1091 Acute Stroke (30分) PAT
采用宽度优先搜索。用一个函数check_chage()检查一个位置是否valid,并且是否stroke,同时将该位置设为访问过。用一个函数neighbors()检查一个位置周围所有的位置中是否有stroke的,放入vector中返回。#include<cstdio>#include<vector>#include<iostream>#inc...原创 2020-04-05 20:45:44 · 131 阅读 · 0 评论 -
1090 Highest Price in Supply Chain (25分)
和1106 Lowest Price in Supply Chain (25分) PAT类似#include<cstdio>#include<vector>#include<iostream>#include<queue>#include<cmath>#define maxn 100100#define inf 1000...原创 2020-04-05 19:47:53 · 152 阅读 · 0 评论 -
1092 To Buy or Not to Buy (20分) PAT
#include<string>#include<iostream>#include<algorithm>#include<cstdio>#include<map>using namespace std;int c[256] = {0}, d[256] = {0};void count_bead(string s...原创 2020-04-05 18:33:42 · 132 阅读 · 0 评论