随笔分类 -  4.2散列

摘要:题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805356599820288 题目比较麻烦,因为限时200ms,所以要用散列。 1 #include<iostream> 2 #include<vector> 3 #i 阅读全文
posted @ 2020-03-22 10:00 tangq123 阅读(187) 评论(0) 推荐(0)
摘要:题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805357933608960 分析: 首先,遍历字符串str,筛选出所有好键,判断好键方法:如果当前字符连续出现的次数不是 k的整数倍,那么标记该字符为好键。 然后,定 阅读全文
posted @ 2020-03-21 11:03 tangq123 阅读(166) 评论(0) 推荐(0)
摘要:英文题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805355358306304 中文题目:https://pintia.cn/problem-sets/994805260223102976/problems/994 阅读全文
posted @ 2020-03-19 17:04 tangq123 阅读(163) 评论(0) 推荐(0)
摘要:英文题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805352359378944 中文题目:https://pintia.cn/problem-sets/994805260223102976/problems/994 阅读全文
posted @ 2020-03-19 11:05 tangq123 阅读(147) 评论(0) 推荐(0)
摘要:英文版题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805352925609984 中文版题目:https://pintia.cn/problem-sets/994805260223102976/problems/9 阅读全文
posted @ 2020-03-18 20:23 tangq123 阅读(166) 评论(0) 推荐(0)
摘要:英文版题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805350803292160 中文版题目:https://pintia.cn/problem-sets/994805260223102976/problems/9 阅读全文
posted @ 2020-03-18 16:46 tangq123 阅读(156) 评论(0) 推荐(0)
摘要:方法一:暴力求解,超时凉凉~~ 1 #include<iostream> 2 #include<unordered_map> 3 #include<vector> 4 #include<algorithm> 5 using namespace std; 6 7 bool cmp(const pair 阅读全文
posted @ 2020-03-17 14:20 tangq123 阅读(269) 评论(11) 推荐(0)
摘要:题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088 方法一: 邻接表存储图,邻接矩阵标记边是否被访问,凉凉~~ 1 #include<iostream> 2 #include<vector> 阅读全文
posted @ 2020-03-16 16:51 tangq123 阅读(209) 评论(0) 推荐(0)
摘要:中文版 1085 PAT单位排行 无需构造函数,快速初始化结构体。 1 #include<iostream> 2 #include<cctype> 3 #include<vector> 4 #include<unordered_map> 5 #include<algorithm> 6 using n 阅读全文
posted @ 2020-03-14 18:39 tangq123 阅读(111) 评论(0) 推荐(0)
摘要:考察数据结构书上的hash的内容。 大致题意就是给出一组元素,按照哈希映射公式pos = (Data+k*k) mod Tablesize(哈希表大小为素数)确定可插入元素位置并插入,如果无法插入,就按行输出这个元素。 然后再给出一组元素,求出查找所有元素的平均查找长度。 注意点: 查找插入位置时, 阅读全文
posted @ 2020-03-14 13:22 tangq123 阅读(274) 评论(0) 推荐(0)
摘要:大致题意就是给出一连串的整数(包含正负),找出未出现过的最小正整数。 1 #include<iostream> 2 #include<map> 3 using namespace std; 4 5 int main() { 6 int n,t,ans = 1; 7 map<int,bool> mp; 阅读全文
posted @ 2020-03-14 11:58 tangq123 阅读(200) 评论(0) 推荐(0)
摘要:这是PAT乙级 1090 危险品装箱 的英文版。 1 #include<iostream> 2 #include<vector> 3 #include<unordered_map> 4 using namespace std; 5 6 int main() { 7 int n,m,g1,g2,K; 阅读全文
posted @ 2020-03-13 15:27 tangq123 阅读(146) 评论(0) 推荐(0)
摘要:在结构体中,不用定义构造函数,实现快速初始化结构体。 struct Student { string ID; int score; } ; vector<Student> v; v.push_back({"我好帅",250}); //快速初始化Student 1 #include<iostream> 阅读全文
posted @ 2020-03-12 21:48 tangq123 阅读(120) 评论(0) 推荐(0)
摘要:麻烦的一批!!!还好题目比较耿直,按要求输出即可,超时就换unordered_map。 新学了小玩意STL-pair,可以理解成一个结构体。 struct pair{ typename1 first; typename2 second; }; 用途: 1.可以代替二元结构体及其构造函数,节省编码时间 阅读全文
posted @ 2020-02-26 17:44 tangq123 阅读(122) 评论(0) 推荐(0)
摘要:hash就完事了。 1 #include"iostream" 2 using namespace std; 3 4 //由于字符本身是整数,所以用hash判断字符是否是第一次输出 5 bool hashtable[300]= {false}; 6 int main() { 7 string s1,s 阅读全文
posted @ 2020-02-26 17:30 tangq123 阅读(175) 评论(0) 推荐(0)
摘要:hash就完事了。 新学一招,关于 map<int,vector<int> >的元素的访问。 1 #include<iostream> 2 #include<vector> 3 #include<unordered_map> 4 using namespace std; 5 6 int main() 阅读全文
posted @ 2020-02-26 17:11 tangq123 阅读(186) 评论(0) 推荐(0)
摘要:hash就完事了。 #include<iostream> using namespace std; bool hashtable[10010] = {false}; int main() { int n,cnt = 0; cin>>n; for(int i = 1; i <= n; ++i) { i 阅读全文
posted @ 2020-02-26 10:08 tangq123 阅读(198) 评论(0) 推荐(0)
摘要:hash题。 我刚开始用map做的,因为map按关键字 递减排序,所以我以为倒着输出就可以。代码如下。 结果有的数据根本就无法输出,比如, 输入:2 输入:1 2 输出:(什么也没有) 后来请教了群里的大佬,说有一个反向迭代器。比较简单,比正向迭代器多加一个字母 r ,代码如下。 1 #includ 阅读全文
posted @ 2020-02-25 19:49 tangq123 阅读(190) 评论(0) 推荐(0)
摘要:这是一道常规体了。 PAT乙级最后一道大题一般是 结构体+排序 +字符串+hash。 1 #include<iostream> 2 #include<unordered_map> 3 #include<algorithm> 4 #include<cmath> 5 using namespace st 阅读全文
posted @ 2020-02-25 16:51 tangq123 阅读(194) 评论(0) 推荐(0)
摘要:hash题。 解题方法:一边输入数据,一边进行判断和输出。 #include<iostream> using namespace std; bool hashtable[10000] = {false}; int main() { int n,m,temp,cnt1 = 0,cnt2 = 0; ci 阅读全文
posted @ 2020-02-24 18:12 tangq123 阅读(140) 评论(0) 推荐(0)