自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(124)
  • 收藏
  • 关注

原创 记录OpenCL学习(C++ API1.1与1.2版本不兼容问题)

Nvidia1050显卡,OpenCL1.2

2022-11-06 10:44:20 502

原创 CLION openCL C/C++环境配置(两个坑)

CLION 配置 OpenCL环境 基于书籍opencl in action代码

2022-11-05 15:51:56 1143 2

原创 CLION配置CUDA环境

windows下CLION的CUDA环境配置

2022-08-20 19:39:09 3075 5

原创 408并查集新考点代码手撸

简单的测试了一下 有毛病的反馈给我 压缩路径和合并优化以后 时间复杂度是O(α(n)) 甚至优于O(logn) 希望今年408考一下 那就美滋滋了#include<bits/stdc++.h>using namespace std;const int Maxsize = 100;int father[Maxsize];// father[i]的绝对值表示此结点下有多少个子结点void Initial(int father[],int n) { for(int i

2021-12-04 23:09:22 1038

原创 408快排模板(简单的的测试代码)

随着时间的推移,观察到408真题的大题中已经不提供有序的数据了 因此很多时候需要自己将数据排序,因为不能调用接口,所以要自己默写快排,以上就是快排的模板 时间复杂度O(nlogn) 空间复杂度O(logn) 算法是不稳定的算法另外 排序算法与初始序列无关的算法有一堆(堆排序)乌龟(归并排序)选(选择排序)基(基数排序)友(摘自牛友 sunlight_run)#include<bits/stdc++.h>using namespace std;int parition(int a

2021-11-25 13:38:19 1250

原创 2019 408真题two points

这道题要求用空间复杂度为O(1)的算法,不用额外的数组空间,显然一定是对单链表的逆置,408对这点考察的频率特别高,需要多加锻炼,以及默写快排。#include<bits/stdc++.h>using namespace std;typedef struct node { int data; struct node* next;}NODE;// 将链表的后半段逆置以后插入前半段void change_list(NODE* h) { NODE *fast,*

2021-11-25 13:18:27 166

原创 根据二叉树的中序和层序遍历还原二叉树(PAT尚未考过)

#include<bits/stdc++.h>using namespace std;const int MAXN = 50;struct node { node* left; node* right; int data;};vector<int> level;int in[MAXN];int n;node* create(vector<int> level,int inl,int inr) { if (level.siz

2021-09-10 15:16:00 234

原创 PAT甲级线上考试备考

我本人刷了两遍题库 之前考了两次都是四十几分,我认为目前甲级题库已经过时了 (对于有算法基础的同学来说) 前100题没有做的必要 除非是典型算法。DFS 和 回溯是相当重要的考点,如果有时间的话一定要多做,明天就是PAT甲级2021秋季考试,目前准备报考浙江大学的研究生,希望能考一个相对好一点的分数,准备要全面,不要遗漏算法笔记上的任何一个知识点,我最短路径只学了dijkstra一个算法 也没有复习堆 最后丢了50分 很遗憾 这次我没有刷甲级题库 做的是力扣上的题目,开拓自己的思路。树,图,关键

2021-09-10 11:38:09 599

原创 浙江大学软件学院2020年保研真题Distance of Triples (25 分)

时间限制:300 ms 内存限制:64 MBThe distance of triples (三元组) (a,b,c) is defined as D(a,b,c)=∣a−b∣+∣b−c∣+∣c−a∣. Now given three non-empty integer sets S1, S2 and S3, you are supposed to find the minimum distance of all the possible triples (a,b,c) where a∈S1, b∈S2

2021-09-07 18:21:55 525

原创 王道书上的排序简单实现 基于vector 陆续完善中

#include<bits/stdc++.h>using namespace std;void shellSort(vector<int>& a,int n) { // DK表示的是希尔排序中的增量 for(int dk = n / 2;dk >= 1;dk /= 2) { for(int i = dk + 1;i < n;i++) { if (a[i] < a[i - dk]) {

2021-07-18 19:12:11 158

原创 力扣101

#include<bits/stdc++.h>using namespace std;// Definition for a binary tree node.struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode() : val(0), left(nullptr), right(nullptr) {} TreeNode(int x) : val(x), left(

2021-04-18 16:19:06 119

原创 力扣100

给你两棵二叉树的根节点 p 和 q ,编写一个函数来检验这两棵树是否相同。如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。#include<bits/stdc++.h>using namespace std;// Definition for a binary tree node.struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode() : val(

2021-04-18 15:47:10 255

原创 力扣26

刷完甲级题库以后PAT还是没考好 有时间的话刷一刷力扣提升自己能力给你一个有序数组 nums ,请你 原地 删除重复出现的元素,使每个元素 只出现一次 ,返回删除后数组的新长度。不要使用额外的数组空间,你必须在 原地 修改输入数组 并在使用 O(1) 额外空间的条件下完成。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array著作权归领扣网络所有。商业转载请联系官方授权,非商业转

2021-04-18 15:32:06 183

原创 基于堆栈的括号匹配算法

参考了王道的答案,但是显然这个程序只考虑了合法输入,对于非法输入会有 一定的问题#include<bits/stdc++.h>using namespace std;//王道书上的正确解法stack<char> s;bool ismatch(const char *str){ int i = 0; while(str[i] != '\0') { char t; switch (str[i]) {

2021-04-17 11:37:54 143

原创 王道堆栈课本实现 测试了创建和初始化函数

#include<bits/stdc++.h>using namespace std;#define MaxSize 50typedef int ElemType;typedef struct{ ElemType data[MaxSize]; //存放栈中元素 int top; //栈顶指针}sqStack;void InitStack(sqStack &s){ s.top = -1;}bool StackEmpty(sqStack S){

2021-04-05 22:11:57 201

原创 王道书上单链表的基本实现

#include<bits/stdc++.h>using namespace std;typedef int Element;typedef struct LNode{ Element data; struct LNode* next;}LNode,*LinkList;// LNode * L //声明一个指向单链表第一个结点的指针// LinkList L; //声明一个指向单链表第一个结点的指针 可读性更强LinkList List_HeadInsert(L

2021-04-02 20:16:42 249

原创 关于递归删除链表结点时为什么不会出现断链问题

void delteX(LinkList &L,int x){ LNode *p; if(L == NULL) { return ; } if(L -> data == x) { p = L; L = L -> next; free(p); delteX(L,x); } else { delteX(L -> nex

2021-04-02 20:08:36 832 1

原创 PAT甲级题解 1131 DFS

遇到数据处理比较困难的就先处理数据 把它映射到相应的数据结构里面 这里把两个站点之和映射到line指定的线上 然后每次遍历路径的时候计算出有多少次换乘以后再和最大的进行比较 说起来难度不大 但是如果要上手的话应该就不一样了 还得自己再多写几遍才行#include<bits/stdc++.h>using namespace std;const int MAXN = 10010;vector<int> G[MAXN];unordered_map<int,int&gt

2021-03-13 10:02:11 178

原创 PAT甲级DFS复习 1034

做了之前的卷子 感觉DFS还是不够熟练 需要多锻炼锻炼 如果有多个参数在DFS之中的话 要注意递归的边界 以及vis数组的值的问题 感觉还是挺难的 今天就考试了 加油#include<bits/stdc++.h>using namespace std;const int MAXN = 1010;int G[MAXN][MAXN];map<string,int> strToint;map<int,string> intTostr;int n,thresho

2021-03-13 09:15:46 112

原创 PAT甲级题解 1151

主要是怎么寻找到根结点 根据根节点的位置去判断 还是挺难的 希望明天考试加油#include<bits/stdc++.h>using namespace std;const int MAXN = 10010;int pre[MAXN];int in[MAXN];map<int,int> mp;void lca(int inl,int inr,int prel,int a,int b){ if(inl > inr) { retu

2021-03-12 16:47:11 137

原创 PAT甲级题解 1142

你尽管暴力 剩下的交给奇迹…#include<bits/stdc++.h>using namespace std;const int MAXN = 220;int father[MAXN];int rootNum[MAXN];int G[MAXN][MAXN];void init(){ for(int i = 0;i<MAXN;i++) { father[i] = i; }}int findfather(int x){

2021-03-12 15:21:09 94

原创 PAT甲级题解 1140

字符串处理问题#include<bits/stdc++.h>using namespace std;const int MAXN = 50;string a[MAXN];char digit[10] = {'0','1','2','3','4','5','6','7','8','9'};string next(string s,int n){ for(int i = 1;i<n;i++) { string t; for(int

2021-03-12 14:50:50 93

原创 PAT甲级题解 1139

是一道比较难的模拟题 要注意同姓 以及朋友不能是情侣 以及。%04d 这题非常难…#include<bits/stdc++.h>using namespace std;const int MAXN = 10010;unordered_map<int,bool> arr;vector<int> G[MAXN];struct node{ int a; int b;};bool cmp(node x,node y){ if(x.a

2021-03-12 11:36:39 144

原创 PAT甲级题解 1135 判断是否是红黑树

需要递归的去求解 来保证结果正确 如果直接DFS可能不行#include<bits/stdc++.h>using namespace std;struct node{ int data; node* left; node* right;};node* insert(node*& root,int data){ if(root == NULL) { root = new node; root ->

2021-03-12 10:14:22 128

原创 PAT甲级题解 1125

排序题#include<bits/stdc++.h>using namespace std;const int MAXN = 10011;int a[MAXN];int main(void){ freopen("pat0314/in.txt","r",stdin); int n; cin>>n; for(int i = 0;i<n;i++) { cin>>a[i]; } sort(a

2021-03-11 18:48:18 84

原创 PAT甲级题解 1123

注意AVL树的写法 要牢记 旋转的时候返回的是temp 插入以后再旋转 旋转只要根节点旋转就好了 旋转最后返回值是根结点#include<bits/stdc++.h>using namespace std;struct node{ int data; node* left; node* right;};int getheight(node* root){ if(root == NULL) { return 0; }

2021-03-11 17:42:50 79

原创 PAT甲级题解 1122

注意判断给出是不是环 再判断是不是回路#include<bits/stdc++.h>using namespace std;const int MAXN = 220;int G[MAXN][MAXN];vector<int> path;int main(void){ freopen("pat0314/in.txt","r",stdin); int N,M; cin>>N>>M; for(int i = 0;i&l

2021-03-11 16:43:37 77

原创 PAT甲级题解 1120

水题 用字符串处理更简单一点#include<bits/stdc++.h>using namespace std;const int MAXN = 10100;map<int,int> happen;vector<int> ans;map<int,bool> in;int main(void){ freopen("pat0314/in.txt","r",stdin); int n; cin>>n; f

2021-03-11 16:23:32 72

原创 PAT甲级题解 1138 (树的遍历)

根据遍历还原这棵树#include<bits/stdc++.h>using namespace std;const int MAXN = 50050;struct node{ int data; node* left; node* right;};int pre[MAXN];int in[MAXN];vector<int> post;node* create(int inl,int inr,int prel,int prer){

2021-03-11 16:05:11 130

原创 PAT甲级题解 1119

根据前序和后序来确定中序是否是唯一的 如果一个数他在根结点旁边 那么就无法判断它是否是左右子树 这个时候就得重新考虑了#include<bits/stdc++.h>using namespace std;const int MAXN = 50;struct node{ int data; node* left; node* right;};bool flag = true;vector<int> in;int pre[MAXN];int

2021-03-11 15:38:49 105

原创 PAT甲级题解 1117

这道题实际上就是一道排序题 看数据量的话用O(n^2)的时间复杂度是过不了的 但是可以采用排好序一次遍历的方法 这样就能节约很多时间#include<bits/stdc++.h>using namespace std;const int MAXN = 100010;int a[MAXN];bool cmp(int a,int b){ return a > b;}int main(void){ freopen("pat0314/in.txt","r",st

2021-03-11 10:52:49 140

原创 PAT甲级题解 1116

注意这个题目要用多个map去hash才能保证正确 慢慢来就好了#include<bits/stdc++.h>using namespace std;const int MAXN = 100010;struct node{ string name; int rank;}Node[MAXN];map<string,int> happen;map<string,int> ranklist;bool is_prime(int n){ i

2021-03-11 10:23:35 131

原创 PAT甲级题解 1115

注意DFS和insert函数的写法 难度也没有特别高#include<bits/stdc++.h>using namespace std;const int MAXN = 1010;struct node{ int data; node* left; node* right; }Node[MAXN];node* insert(node* &root,int data){ if(root == NULL) {

2021-03-11 10:09:26 108

原创 PAT甲级 1113

排序题 很简单的…#include<bits/stdc++.h>using namespace std;const int MAXN = 100010;int a[MAXN];int main(void){freopen(“pat0314/in.txt”,“r”,stdin);int n;cin>>n;for(int i = 0;i<n;i++){cin>>a[i];}int s1 = 0;int s2 = 0;int num1 =

2021-03-11 10:08:34 86

原创 PAT甲级题解 1112

可以在前面加一个作为辅助判断#include<bits/stdc++.h>using namespace std;unordered_map<char,bool> mp;unordered_map<char,bool> alreayright;unordered_map<char,bool> happen;int main(void){ freopen("pat0314/in.txt","r",stdin); int n;

2021-03-10 19:59:35 99

原创 PAT甲级题解 1110

CBT的性质是最大的下表刚刚好是和结点个数相同的 否则一定是大于的 利用这个性质去DFS解#include<bits/stdc++.h>using namespace std;const int MAXN = 25;struct node{ int left = -1; int right = -1;}Node[MAXN];//完全二叉树的最大下表 一定等于节点数bool notroot[MAXN];int maxindex = -1;int ans;voi

2021-03-10 18:37:19 101

原创 PAT甲级题解 1109

注意左右顺序 还有这个排列的顺序 以及每排是N / K个的#include<bits/stdc++.h>using namespace std;const int MAXN = 1010;struct node{ string name; int height;}Node[MAXN];bool cmp(node a,node b){ if(a.height != b.height) { return a.height > b.

2021-03-10 17:17:32 104

原创 PAT甲级题解 1107并查集

复习一遍并查集 用并查集做这个题目 效率看起来是比DFS要高一点的#include<bits/stdc++.h>using namespace std;const int MAXN = 10010;vector<int> G[MAXN];int numCnt = 0;int n;int num = 0;bool vis[MAXN];void DFS(int u){ vis[u] = true; if(u < n) {

2021-03-10 16:16:13 100

原创 PAT甲级题解 1108

本来是判断字符串格式 但是最后一个点过不了 就看了柳神的代码用sscanf sprintf了#include<bits/stdc++.h>using namespace std;const int MAXN = 110;string s[MAXN];double tempAns;// bool isleagle(string s)// {// int index = -1;// int cntdian = 0;// int flag = 1;//

2021-03-10 15:47:14 159

原创 PAT甲级题解 1107

求连通集的个数 以及连通集内有人的个数 做个映射#include<bits/stdc++.h>using namespace std;const int MAXN = 10010;vector<int> G[MAXN];int numCnt = 0;int n;int num = 0;bool vis[MAXN];void DFS(int u){ vis[u] = true; if(u < n) { num++;

2021-03-10 14:09:30 158

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除