- 博客(36)
- 收藏
- 关注
原创 1021 Deepest Root (25分) 采用BFS
#include<iostream>//AC,采用的bfs,导致一开始内存超限#include<set>//bfs与dfs的区别https://blog.csdn.net/yueguangmuyu/article/details/100046125#include<vector>#include<queue>#include<algorithm>using namespace std;#define INF 0x3f3f3f3fcon
2020-09-04 17:51:10
147
原创 19年冬季Pat甲级
7-1#include<iostream>#include<vector>#include<string>#include<algorithm>using namespace std;const int maxn = 27;string cap[maxn][7];void Print(string s) { vector<string> ans; for (int i = 0; i < s.size(); i++) {
2020-09-04 16:03:49
103
原创 1033 To Fill or Not to Fill (25分)
真复杂。。。#include<iostream>//AC//建议看算法笔记#include<cmath>#include<algorithm>#include<vector>using namespace std;const int maxn = 550;double gasCap, dsum, disPerGas;int n;struct node { double price, d;};bool cmp(node a, node b
2020-07-23 20:53:16
93
原创 1075 PAT Judge (25分)
很麻烦,花了一个小时,最后一个点过不去又找了很长时间错误,这种奇坑的阅读理解题看看就好#include<iostream>#include<vector>//从来没提交过题的人和没有一题通过编译的人不输出,但是通过编译即使全部为0依然要输出(否则最后一个测试点过不去)(算法笔记有一个样例,可以试试)#include<algorithm>//如果要输入,没通过编译的题输出0,没提交过的题输出-using namespace std;const int maxn =
2020-07-20 16:41:49
130
原创 1107 Social Clusters (30分)
题目本身不难,但是由于对并查集的路径压缩理解有误,导致改了很长时间#include<iostream>#include<algorithm>using namespace std;const int maxn = 1100;int father[maxn], hobby[maxn] = { 0 };bool cmp(int a, int b) { return a > b; }void init() { for (int i = 0; i < maxn;
2020-07-16 16:44:40
77
原创 1018 Public Bike Management (30分)
用贪心的思想,25分,5和7测试点错误,原因如下#include<iostream>#include<vector>#include<algorithm>using namespace std;#define INF 0x3f3f3f3fconst int maxn = 550;int c, n, e, m;int G[maxn][maxn], vis[maxn], d[maxn];int weight[maxn], w[maxn];vector<
2020-07-14 17:52:00
103
原创 1087 All Roads Lead to Rome (30分)
#include<iostream>//27分,一个点错误#include<vector>#include<unordered_map>#include<algorithm>using namespace std;#define INF 0x3f3f3f3fconst int maxn = 220;int G[maxn][maxn], d[maxn], vis[maxn];int weight[maxn], w[maxn];//点权int n
2020-07-14 09:56:53
205
原创 1151 LCA in a Binary Tree (30分) 段错误
通过dfs,分别求出从根节点到两个节点的路径,然后比较分析结果29分 第二个测试点段错误#include<iostream>#include<vector>#include<stack>#include<algorithm>using namespace std;const int maxn = 1e4 + 10;int n, m;int in[maxn], pre[maxn], visit[maxn] = { 0 };struct nod
2020-07-11 17:25:49
222
原创 1110 Complete Binary Tree (25分)
层序遍历#include<iostream>#include<queue>#include<string>#include<algorithm>using namespace std;const int maxn = 30;int N, root = 0, ans;int visit[maxn] = { 0 };struct node { int l, r;}tree[maxn];queue<int> q;bool jud
2020-07-10 16:34:15
61
原创 1021 Deepest Root (25分)
超时+错误标准思路⾸先深度优先搜索判断它有⼏个连通分量。如果有多个,那就输出Error: x components,如果只有⼀个,就两次深度优先搜索,先从⼀个结点dfs后保留最⾼⾼度拥有的结点们,然后从这些结点中的其中任意⼀个开始dfs得到最⾼⾼度的结点们,这两个结点集合的并集就是所求#include<iostream>#include<vector>#include<set>#include<algorithm>using namespace
2020-07-09 20:48:16
134
原创 1020 Tree Traversals (25分)及相关题型
Pat链接经典题型常规的建树法#include<iostream>//AC#include<vector>#include<queue> using namespace std;const int maxn = 50;int N;int post[maxn], in[maxn];struct node { int value; node* left; node* right;}tree[maxn];node* Creattree(int
2020-07-09 14:22:51
132
原创 1056 Mice and Rice (25分)
1056 Mice and Rice (25分)参考题目读了好久都没读明白。。。看了上方链接的解释才懂什么意思,感觉好绕。。。第二行为0~n-1的老鼠重量,第三行为合并的次序序号,最后按0到n-1输出排行排行为1 2 2 4形式#include<iostream>#include<vector>#include<cmath>#include<...
2020-02-19 19:33:35
122
原创 1101 Quick Sort (25分)
1101 Quick Sort (25分)更好的题解#include<iostream>//AC#include<vector>#include<algorithm>using namespace std;const int maxn = 1e5 + 10;int main() { int n, a[maxn]; cin >> n;...
2020-02-18 20:26:07
77
原创 1089 Insert or Merge (25分)
1089 Insert or Merge (25分)这种题总是想很长时间#include<iostream>#include<vector>#include<algorithm>using namespace std;int main() { int n, a[110] = { 0 }, b[110] = { 0 }, flag = 0; cin...
2020-02-17 20:58:46
72
原创 1044 Shopping in Mars (25分)
1044 Shopping in Mars (25分)边听歌边写,感觉写的很乱,结果一次就过了,意外之喜!思路:不断累加直至sum大于或等于price,判断并决定是否存入ans数组,然后退出循环,sum减去头和尾的值,从尾处继续累加防止超时。。。代码:可读性有点差#include<iostream>#include<cstdio>#include<vec...
2020-02-16 21:50:32
89
原创 1038 Recover the Smallest Number (30分)
1038 Recover the Smallest Number (30分)不太会sort比较函数的写法#include<iostream>//AC#include<vector>#include<string>#include<algorithm>using namespace std;int com(string& a, s...
2020-02-15 16:47:08
98
原创 1075 PAT Judge (25分)
1075 PAT Judge (25分)题目很难读,坑点多,最后两个测试点过不去,在牛客网倒是能过,实在找不到,就先这样吧#include<cstdio>#include<vector>#include<algorithm>using namespace std;struct node { int id, sum = -1, flag = 0, p...
2020-02-15 11:04:43
186
原创 1080 Graduate Admission (30分)
1080 Graduate Admission (30分)#include<cstdio>//AC#include<vector>#include<algorithm>using namespace std;struct node { int id, g1, ave; vector<int> sch;};int quote[110]...
2020-02-14 17:30:53
131
原创 1055 The World's Richest (25分)
1055 The World’s Richest (25分)试着直接排序遍历,并用scanf printf输入输出节省时间,居然过了,500ms最高用了450ms!不过scanf输入string时出了个问题: scanf("%s%d%d", temp.name.c_str(), &temp.age,&temp.w);//此时查看结构体内的name时,是完全正确的,但是用so...
2020-02-13 23:01:23
86
原创 1016 Phone Bills (25分)
1016 Phone Bills (25分)花了一个小时写完代码,但由于计算花费的时候思维混乱,WA后改了半个小时才过#include<iostream>#include<cstdio>#include<string>#include<vector>#include<algorithm>using namespace std...
2020-02-13 14:32:23
111
原创 1095 Cars on Campus (30分)
1095 Cars on Campus (30分)题目一开始没读懂。。。总是想着用时间复杂度最低的,反而大大影响解题,归根结底还是对运行时间把握不到位。注意点:配对要求是,如果⼀个车多次进入未出,取最后一个值;如果⼀个车多次out未进入,取第⼀个值。⼀个车可能出入校园好多次,停车的时间应该取之和。#include<cstdio>#include<iostream&...
2020-02-12 13:15:01
113
原创 1012 The Best Rank (25分)
1012 The Best Rank (25分)注意点:排名为111456不是111234代码:#include<iostream>//AC#include<vector>#include<cmath>#include<algorithm>using namespace std;const int maxn = 1e7;struc...
2020-02-11 12:22:35
75
原创 1121 Damn Single (25分)
1121 Damn Single (25分)#include<cstdio>#include<vector>#include<algorithm>using namespace std;const int maxn = 1e6+10;int Hash[maxn] = { 0 }, exist[maxn] = { 0 };int main() { ...
2020-02-11 10:54:04
69
原创 1088 Rational Arithmetic (20分)
1088 Rational Arithmetic (20分)思路:和1081同一类型,一开始担心超过long long表示范围,就按照1081那样通分计算,写了几十行写不下去了,乖乖看了柳神的(柳神tql),发现是自己想多了。。。代码:#include<cstdio>#include<cmath>#include<algorithm>using n...
2020-02-09 17:35:31
224
原创 1029 Median (25分)
1029 Median (25分)思路:参考的柳神代码一定要用scanf,否则最后一个点超时代码:#include<iostream>#include<cstdio>#include<vector>using namespace std;int main() { int n, m, t; int num[200005]; cin >...
2020-02-07 16:01:15
196
原创 1017 Queueing at Bank (25分)
1017 Queueing at Bank (25分)思路:写的有点乱,坑点有点多…具体在注释。代码:#include<iostream>//AC#include<vector>#include<string>#include<algorithm>using namespace std;int trans(string str) {...
2020-02-06 20:11:42
125
原创 1031 Hello World for U (20分)
1031 Hello World for U (20分)代码:#include<iostream>//AC#include<string>using namespace std;int main() { string str; getline(cin, str); int len = str.size(); int a, b; a = (len + 2)...
2020-02-05 22:17:21
65
原创 1069 The Black Hole of Numbers (20分)
For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by takin...
2020-02-05 22:15:18
57
原创 1073 Scientific Notation (20分)
Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [±][1-9].[0-9]+E[±][0-9]+ which means that the intege...
2020-02-05 22:10:20
133
原创 1014 Waiting in Line (30分)
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:The space...
2020-02-05 19:23:10
80
原创 1071 Speech Patterns (25分)
People often have a preference among synonyms of the same word. For example, some may prefer “the police”, while others may prefer “the cops”. Analyzing such patterns can help to narrow down a speaker...
2020-02-05 11:42:31
148
原创 1112 Stucked Keyboard (20分)
题目:On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the characters corresponding to those keys will appear repeatedly on screen for k times.Now given a res...
2020-02-04 17:47:28
135
原创 1047 Student List for Course (25 分)
题目:Zhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses.Inpu...
2020-02-04 16:11:59
125
原创 Pat_甲级:1065 A+B and C (64bit) (20 分)
题目:1065 A+B and C (64bit) (20分)Given three integers A, B and C in [−263,263], you are supposed to tell whether A+B>C.Input Specification:The first line of the input gives the positive num...
2020-02-03 17:33:32
153
原创 PAT乙级_1052 卖个萌 (20分)
萌萌哒表情符号通常由“手”、“眼”、“口”三个主要部分组成。简单起见,我们假设一个表情符号是按下列格式输出的:[左手]([左眼][口][右眼])[右手]现给出可选用的符号集合,请你按用户的要求输出表情。输入格式:输入首先在前三行顺序对应给出手、眼、口的可选符号集。每个符号括在一对方括号 []内。题目保证每个集合都至少有一个符号,并不超过 10 个符号;每个符号包含 1 到 4 个非空字符。...
2020-01-30 11:30:59
81
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人