蓝桥杯知识点总结
1.贪心算法:有关最优的都是它
2.只要提取出诸如(a1+a2+a3...)时候,用前缀和
2.标准库
用万能头文件#include <bits/stdc++.h>
vector<int> nums = {1, 2, 3, 4, 5}; vector<int>::iterator it; for(it = nums.begin(); it != nums.end(); it++) { cout << *it << " "; // 输出: 1 2 3 4 5 }
vector<int> v(5,2);//长度为五,所有元素都为2 v.push_back(x);//在末尾添加元素x v.pop_back();//删除队尾元素 v.size();//返回元素个数
set<int> s; s.insert(x);//插入元素x(插入的元素不能重复,重复了只会保留一个) s.erase(x);//删除元素 s.count(x);//统计元素x的个数 s.size(); // 返回元素个数 s.empty(); // 判断集合是否为空,返回真则为空
map<string, int> m; // 创建空map(前一个代表key,后一个代表value,一个map对应唯一一个value) m[key] = value; // 插入或修改键值对 m.erase(key); // 删除键值对 m.count(key); // 统计键的个数(0或1) m.size(); // 返回键值对个数 m.empty(); // 判断map是否为空,返回真则为空
queue<int> q; // 创建空队列 q.push(x); // 将x加入队尾 q.pop(); // 删除队首元素 q.front(); // 获取队首元素 q.back(); // 获取队尾元素 q.size(); // 返回元素个数 q.empty(); // 判断队列是否为空,返回真则为空
priority_queue<int> pq; // 创建空优先队列 pq.push(x); // 插入元素x pq.pop(); // 删除最大元素 pq.top(); // 获取最大元素 pq.size(); // 返回元素个数 pq.empty(); // 判断队列是否为空,返回真则为空
// set的二分查找 set<int> s; s.lower_bound(x); // 返回大于等于x的第一个元素的迭代器,如果不存在,则返回 s.end() s.upper_bound(x); // 返回大于x的第一个元素的迭代器,如果不存在,则返回 s.end() // map的二分查找 map<int, string> m; m.lower_bound(x); // 返回key大于等于x的第一个元素的迭代器,如果不存在,则返回 m.end() m.upper_bound(x); // 返回key大于x的第一个元素的迭代器,如果不存在,则返回 m.end() //例子 set<int> s = {1, 3, 5, 7, 9}; auto it = s.lower_bound(4); // it指向5 cout << *it << endl; // 输出: 5 map<int, string> m; m[1] = "one"; m[3] = "three"; m[5] = "five"; auto it2 = m.lower_bound(2); // it2指向key为3的元素 cout << it2->first << " " << it2->second << endl; // 输出: 3 three
3.高精度
实在不行直接用long long,能拿多少分算多少分
有时间就背背语法
4.链表
#include<stdio.h> #include<stdlib.h> #include<string.h> #include <iostream> using namespace std; struct student{ int id; char name[101]; int result; struct student *next;//结构体指针,用于指向下一个结构体 }; typedef struct student stu; int main(){ stu *head,*tail,*p; p=(stu*)malloc(sizeof(stu));//分配一个地址 head=p; tail=p; head->next=NULL;//为了让最后一个指针的next可以正确指引退出,要使之为负 cin>>p->id; while(p->id!=0){ cin>>p->name; cin>>p->result; p=(stu*)malloc(sizeof(stu));//分派新的空间 tail->next=p;//让上一个结构体可以正确指向下一个 tail=p;//更新地址 tail->next=NULL;//使之可以正确退出 cin>>p->id; } p=head; while(p!=NULL){ if(p->id!=0)cout<<p->id<<" "<<p->name<<" "<<p->result<<endl; p=p->next; } return 0; }