- 博客(32)
- 收藏
- 关注
原创 2020-10-18 LeetCode 1. 两数之和
主要考点:unordered_mapclass Solution {public: vector<int> twoSum(vector<int>& nums, int target) { // 哈希 unordered_map<int,int> hashtable; for(int i=0;i<nums.size();i++){ auto itr=hashtable.fi
2020-10-18 16:24:44
93
原创 LeetCode 19. 删除链表的倒数第N个节点
题目主要考的是:快慢指针的应用 哑节点 dummyhead /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, L
2020-10-18 15:51:52
118
原创 PAT甲级 1118 Birds in Forest (25分) 并查集
题目中规中矩,没有什么难度,标准的并查集就能拿下。#include<iostream>#include<vector>using namespace std;int father[10010];int findFather(int x) { int a = x; while (x != father[x]) { x = father[x]; } while (a != father[a]) { int z = a; father[a] = x; .
2020-07-24 15:24:02
112
原创 PAT甲级 1126 Eulerian Path (25分) 测试点问题
这题没啥难度,理解题意即可,这里需要注意的是需要DFS判断连通图的数量,不是1的直接输出“Non-Eulerian”#include<iostream>using namespace std;int V, E;int degree[505] = { 0 };int G[505][505] = { 0 };bool vis[505] = { false };void DFS(int now) { vis[now] = true; for (int i = 1; i <.
2020-07-24 11:17:30
285
原创 PAT甲级 1149 Dangerous Goods Packaging (25分)
#pragma warning(disable:4996)#include<iostream>#include<unordered_map>#include<vector>using namespace std;const int maxn = 100010;unordered_map<int, vector<int> > mp;int N, M;bool appear[maxn] = { false };int main() .
2020-07-21 15:15:54
173
原创 PAT 1152 Google Recruitment (20分)
#include<iostream>#include<string>#include<iomanip>using namespace std;string s;bool isPrime(int n) { if (n <=1)return false; if (n == 2)return true; int sqr = sqrt(n); for (int i = 2; i < sqr + 1; i++) { if (n%i == 0)re.
2020-07-20 23:39:59
106
原创 PAT刷题记录 1069 The Black Hole of Numbers (20分)
#include<iostream>#include<string>#include<sstream>#include<algorithm>#include <iomanip>using namespace std;/* 简单总结: 1. string stream 需要头文件<sstream> 1) stringstream ss; 2) ss.str() //转换成string类型 可用来初始化st.
2020-07-15 18:44:58
100
原创 PAT刷题记录 1033 To Fill or Not to Fill (25分)
#include<iostream>#include<string>#include<algorithm>using namespace std;/* 总结:这题较难,再看几遍 注意点: 1.起点可能没加油站 2.把终点站加入,更方便处理 3.退出条件: 1.达到终点站 2.中途,不能满油也无法达到下一个加油站 4.加油站的选取: 1.当前油价在可达范围内最低,加满(MAX-剩余) 2.可达范围内,有比当前低的,加油情况: 1.
2020-07-14 21:54:50
103
原创 PAT刷题记录 1095 Cars on Campus (30分)
#pragma warning(disable:4996)#include<vector>#include<iostream>#include<string>#include<algorithm>#include<map>using namespace std;struct record { string name; int hh, mm, ss; int time; // 用second来存储总时间 bool sta.
2020-07-14 16:45:43
96
原创 PAT刷题记录 1083 List Grades (25分)
#include<iostream>#include<string>#include<algorithm>using namespace std;struct student { string name; string id; int grade;}stu[10000];bool cmp(student a,student b) { return a.grade > b.grade;}int main() { int n; int .
2020-07-14 15:35:45
91
原创 PAT刷题记录 1025 PAT Ranking (25分)
#include<iostream>#include<vector>#include<algorithm>#include<string>using namespace std;/* 总结: 用vector的insert来进行合并操作*/struct Student { string id; int grade; int location_number; int local_rank; int final_rank;};.
2020-07-14 10:14:02
99
原创 PAT刷题记录 1005. Spell It Right (20分)
#include<iostream>#include<string>using namespace std;string num[10] = { "zero","one","two","three","four","five","six","seven","eight","nine"};string N;int main() { cin >> N; long sum=0; int result[100]; int size = N.size(.
2020-07-13 15:27:14
135
原创 PAT刷题记录 1073. Scientific Notation (20分)
#include<iostream>#include<string>using namespace std;/* 总结: 1.需要注意一下,有时候需要输出小数点 2.string->int: stringtext="152"; intnumber=atoi(text.c_str());*/string s;int main() { cin >> s; int point_pos = s.find('.'); i...
2020-07-13 14:25:35
92
原创 PAT刷题记录 1061. Dating (20分)
#include<iostream>#include<string>using namespace std;/* 题目说的是同一位置,一开始没注意,两层for循环出错了,被坑了半天*/string day[7] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };int main() { string s1, s2, s3, s4; cin >> s1; cin >> s2; cin &.
2020-07-13 13:50:34
127
原创 PAT刷题记录 1027. Colors in Mars (20分)
#include<iostream>/* 总结:写麻烦了点 这里每个数最多只有两位,直接/13得到高位,%13取得低位即可*/using namespace std;char ans[13] = { '0','1','2','3','4','5','6','7','8','9','A','B','C'};int main() { int a[1000]; int temp; for (int i = 0; i < 3; i++) { cin >&g.
2020-07-13 11:45:53
103
原创 PAT刷题记录 1019. General Palindromic Number (20分)
#include<iostream>/* 总结:主要考点在于十进制数如何转化为base进制数,用的是除留余数法*/using namespace std;int num, base;int main() { cin >> num >> base; int a[100]; int cnt = 0; do { a[cnt++] = num % base; num= num / base; } while (num != 0); bool.
2020-07-13 11:21:11
118
原创 PAT刷题记录 1031. Hello World for U (20分)
#include<iostream>#include<vector>#include<string>using namespace std;string input;int main() { cin >> input; int n, n2; int size = input.size(); n = (size + 2) / 3; n2 = size - 2 * n; for (int i = 0; i < n - 1; i+.
2020-07-13 10:29:00
113
原创 PAT刷题记录 1036. Boys vs Girls (25分)
#include<iostream>#include<string>using namespace std;/* 没难度,仅供大家参考*/struct Stu { string name; char gender; string id; int grade;}stu[10005];int N;int main() { cin >> N; int m_cnt=0, f_cnt=0; int high=-1, low=1000; i.
2020-07-13 10:26:01
94
原创 PAT甲级刷题记录 1006.Sign In and Sign Out (25分)
#pragma warning(disable:4996)#include<iostream>#include<string>#include<algorithm>using namespace std;/* 小结:题目比较简单,主要是两个sort有点蠢 可以用两个变量保存最早的时间和对应的index,用两个变量保存最晚的时间和对应的index*/struct Person { string name; int come; int leave.
2020-07-13 10:09:03
155
原创 PAT甲级 1009. Product of Polynomials (25分)
代码参考胡凡笔记#pragma warning(disable:4996)#include<cstdio>#include<vector>using namespace std;/* 总结:这道题关键在于多项式乘积的理解 多项式相乘的结果,指数是两者指数相加,系数相乘 注意点: 1)答案的系数数组要够大,起码大于2000 2)第二个数组不用保存,可以边读边边处理*/struct Poly { int exp; double value;}po.
2020-07-13 09:23:03
133
原创 PAT甲级 1046. Shortest Distance (20分)
要点:用dis数组存放第1个结点到第i个节点的距离,由此可以快速得出,第j个结点到第i个结点的距离,dis[j]-dis[i] (j>i)#include<iostream>#include<algorithm>using namespace std;const int MAXN = 100005;int dis[MAXN], A[MAXN];int N,a,b;int que_num;int main() { cin >> N; int s
2020-07-13 00:18:40
129
原创 PAT甲级 1044.Shopping in Mars (25)
原题链接:https://www.nowcoder.com/pat/5/problem/4083代码参考胡凡笔记简单记录#include<iostream>using namespace std;/* 总结: 这道题考的是连续序列的子序列和 这里可以在输入的时候,用一个辅助数组sum[i] 表示第一个数到第i个数的和值, 避免后续计算的重复计算累加和带来的时间损耗 思路: 遍历左端点 i (1~n) 求出每个左端点所对应的右端点, 关于右端点的求法:这里用...
2020-07-11 21:25:14
106
原创 PAT甲级 1038. Recover the Smallest Number (30)
原题链接:https://www.nowcoder.com/pat/5/problem/4025代码参考胡凡上机笔记作个简单记录#include<iostream>#include<algorithm>#include<string>/* 简单总结: 这道题一开始的思路大家都有,就是个排序问题,问题是cmp怎么写, 一开始我的思路有点问题,可能能够实现,但实现起来较为复杂, 想的是比较两个字符串, 1)如果最高位不同,小的那个在前 2..
2020-07-11 19:47:29
111
原创 PAT打卡第15天 1057. Stack(30)
第一次做这种类型的,用的方法超时了#include<iostream>#include<vector>#include<string>#include<algorithm>using namespace std;int number;vector<int> stack;int exist[100000] = { 0 };void peek_median() { int size = stack.size(); i.
2020-07-05 21:48:25
97
原创 PAT打卡第14天 A1080. Graduate Admission (30)
#pragma warning(disable:4996)#include<iostream>#include<vector>#include<algorithm>using namespace std;/* 题目总结:吐了,总会有这样那样的小问题 题目思路:对所有学生进行排序先,先按照grade,一样时,比较ge,仍一样,说明rank一样 在数组下标问题上浪费了大量的时间 再捋一遍顺序,对vector容器排序后,每个节点应该保存学号index, .
2020-07-04 23:56:34
109
原创 PAT打卡第13天 1079. Total Sales of Supply Chain (25)
原题链接:https://www.nowcoder.com/pat/5/problem/4309#pragma warning(disable:4996)#include<vector>#include<iostream>using namespace std;/* 总结:比较简单,但是犯了个弱智的错误,DFS里的起始temp_price直接赋值1.8了 像个憨憨*/struct node { vector<int> child; int pro
2020-07-03 21:54:34
119
原创 PAT打卡第13天 1078. Hashing (25 分)
原题链接:https://www.nowcoder.com/pat/5/problem/4308#pragma warning(disable:4996)#include<iostream>#include<algorithm>using namespace std;int k[10005];int N, MSize;bool visited[10005];/* 题目总结:主要两个考点 1)判断质数和找下一个质数 (1)注意处理1和2 (2)
2020-07-03 19:31:13
112
原创 PAT打卡第12天 1077. Kuchiguse (20)
#pragma warning(disable:4996)#include<vector>#include<string>#include<algorithm>#include<iostream>using namespace std;/* 题目总结: 1)getline(cin,存string的变量名);来读取带空格的句子 2)reverse(string.begin(),string.end()) 用来反转元素 string .
2020-07-02 22:46:36
114
原创 PAT打卡第11天 1098. Insertion or Heap Sort (25)
//heap sort函数和down adjust函数需要多多练习/* 题目总结: 本题主要考插入排序和堆排序,其中堆排序是难点 1)插入排序:插入排序比较简单,每次从原始序列中选未排序的第一个元素,加入到一个vector容器中 用sort函数进行排序,这里需要注意的是,sort是对容器元素排序,一开始用的数组不行 这里insertion写的比较乱,下次先想好思路,在动手写 2)堆排序:一般分为大根堆和小根堆,这里是大根堆 ...
2020-07-01 23:04:13
143
原创 PAT打卡第10天 1042. Shuffling Machine (20)
原题链接:https://www.nowcoder.com/pat/5/problem/4081#pragma warning(disable:4996)#include<iostream>#include<vector>// 简单总结:// 1)这里如果shuffle_time非常大 vector产生的辅助空间可能非常大 // 好像两个数组就行了,不用vector容器类 不过这个写习惯了// 可以循环覆盖vector card[i][0]和vect
2020-06-30 21:12:26
1421
原创 PAT打卡第9天 1058. A+B in Hogwarts (20)
原题链接:https://www.nowcoder.com/pat/5/problem/4111#pragma warning(disable:4996)#include<iostream>// 题目总结:20分的题目确实简单,花了10分钟,没有什么要注意的int main() { int a1, b1, c1, a2, b2, c2; int a=0,b = 0,c = 0; scanf("%d.%d.%d", &a1, &b1, &c1); s
2020-06-29 19:59:58
98
原创 PAT打卡第8天 1099. Build A Binary Search Tree
/* 题目总结:终于有一道写起来较为顺畅的题目了 这道题主要是考层序遍历和中序遍历和树的构建 1)树的构建: 这里按节点顺序给出每个结点的左右孩子的index, 我这里写的有点麻烦了,用的是vector,按节点压入,每个节点还保存了index 其实没必要,直接创建node类型的NODE[100]数组即可,这里的输入是按顺序输入的,index就是 数组下标 2)中序遍历: 花的时间也不多,主要...
2020-06-28 20:27:25
82
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人