随笔分类 - 4.1排序
摘要:英文题目:1101 Quick Sort 中文题目:1045 快速排序 主元判断方法:如果一个元素大于等于其左边所有元素的最大值,小于等于其右边所有元素的最小值,那么这个元素可能是主元。 1 #include<iostream> 2 #include<algorithm> 3 using names
阅读全文
摘要:英文题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805360043343872 中文题目:https://pintia.cn/problem-sets/994805260223102976/problems/994
阅读全文
摘要:题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805356599820288 题目比较麻烦,因为限时200ms,所以要用散列。 1 #include<iostream> 2 #include<vector> 3 #i
阅读全文
摘要:题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805357258326016 大致题意:给出一个包含n个正整数的集合,把集合分成s1,s2,n1,n2分别是s1,s2的元素个数。要求输出 最小|n1-n2|,最大|s
阅读全文
摘要:方法一:暴力求解,超时凉凉~~ 1 #include<iostream> 2 #include<unordered_map> 3 #include<vector> 4 #include<algorithm> 5 using namespace std; 6 7 bool cmp(const pair
阅读全文
摘要:中文版。 1080 MOOC期终成绩 1 #include<iostream> 2 #include<vector> 3 #include<unordered_map> 4 #include<algorithm> 5 #include<cmath> 6 using namespace std; 7
阅读全文
摘要:中文版 1085 PAT单位排行 无需构造函数,快速初始化结构体。 1 #include<iostream> 2 #include<cctype> 3 #include<vector> 4 #include<unordered_map> 5 #include<algorithm> 6 using n
阅读全文
摘要:在结构体中,不用定义构造函数,实现快速初始化结构体。 struct Student { string ID; int score; } ; vector<Student> v; v.push_back({"我好帅",250}); //快速初始化Student 1 #include<iostream>
阅读全文
摘要:麻烦的一批!!!还好题目比较耿直,按要求输出即可,超时就换unordered_map。 新学了小玩意STL-pair,可以理解成一个结构体。 struct pair{ typename1 first; typename2 second; }; 用途: 1.可以代替二元结构体及其构造函数,节省编码时间
阅读全文
摘要:再次做这道题,收获很多!!! 新技巧get!!!保留结构体的默认构造函数,并构造新的构造函数,用于快速初始化结构体。 用法:结构体名(参数1,参数2,参数3,。。。) 1 #include<iostream> 2 #include<unordered_map> 3 #include<vector>
阅读全文
摘要:这是一道常规体了。 PAT乙级最后一道大题一般是 结构体+排序 +字符串+hash。 1 #include<iostream> 2 #include<unordered_map> 3 #include<algorithm> 4 #include<cmath> 5 using namespace st
阅读全文
摘要:这是一道排序+字符串处理的题目,难度属于PAT乙级,五题中的第三题。 分析:字典序就是字符串在字典中的顺序。例如, 1。“A”的字典序小于“a”; 2。"a"的字典序小于”b“; 3。”aa“的字典序小于”aaaa“ 4。"aaaa"的字典序小于”aab“的字典序,这里从最高位,一个字符一个字符的比
阅读全文
摘要:有种哈夫曼二叉树的思想。 #include<iostream> #include<algorithm> using namespace std; int a[10010] ={0}; int main(){ int n; cin>>n; for(int i = 0 ;i < n;++i) scanf
阅读全文
摘要:hash题。。。 #include<iostream> #include<algorithm> using namespace std; int hashtable[100500]= {0}; int c[100500] = {0}; int main() { int n,a,b,m; cin>>n
阅读全文
摘要:根据题目给的信息,倒着来看,在草稿纸上试试,总的来说,有点麻烦。 #include<iostream> #include<algorithm> using namespace std; struct Student { string name; int height; } stu[10010]; s
阅读全文
摘要:大致题意就是判断给出序列中,哪些元素是主元,即主元元素大于等于其左边的最大值,小于等于其右边的最小值。 例如,1 , 3, 2, 4, 5 1<=1 <=2,所以1是主元。 4<=4<=5,所以4是主元。 5<=5<=INF,所以5是主元。 坑点:输出结束后,必须加一个换行符,不然测试点2显示格式错
阅读全文
摘要:第一种方法。 直接模拟插入排序和非递归的归并排序。。。 #include<iostream> #include<algorithm> using namespace std; int n; int a[111] = {0},b[111]= {0},temp[111] = {0}; bool flag
阅读全文
摘要:没啥好说的,按题意对数据排序输出即可。 STL:vector,string.用cin/cout可能会超时,改成scanf和printf即可。 #include"iostream" #include"algorithm" #include"vector" using namespace std; st
阅读全文

浙公网安备 33010602011771号