学途智助
首页
分类
标签
关于网站
登录
eeettt123
2024-04-13
60
作者编辑
蓝桥杯速记
``打印准考证 ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ``` -std=c++11 ``` 打印准考证 ```c LL qmi(int a,int b,int c){ LL res = 1 ; // %c; while(b){ if(b&1) {res=(LL)res *a %c;} b=b>>1; a=a*(LL)a%c; } return res; } ``` ```c++ struct T{ int l,r; int d; } t[N] ;//默认是 0 void add(int i,int k,int insertleft){ if(insertleft ==1 ){ t[k].r= t[i].r; t[k].l=i; t[i].r=k; t[t[k].r].l=k; } else { t[k].l=t[i].l; t[k].r=i; t[i].l=k; t[t[k].l].r=k; } } ``` 符合直觉的 静态链表的写法啊(双向) ```c++ void dfs(当前状态) { if(当前状态是目标状态) // 判断 进行相应处理(输出当前解、更新最优解、退出返回等) // 扩展 for(所有可行的新状态) { if(新状态没有访问过 && 需要访问) // 可行性剪枝、最优性剪 枝、重复性剪枝 { 标记 dfs(新状态); 取消标记 } } } ``` ```c for(int year=2000;year<=2022;year++) for(int month=1;month<=12;month++) for(int day=1;day<=31;day++) { if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12); else if(month == 2) { if((year%4==0&&year%100!=0) || year % 400 == 0) { if(day > 29) break; } else { if(day > 28) break;} } else { if(day > 30) break; } } ``` 日期 ### pair 排序排那个 first ```c++ std::sort(vec.begin(), vec.end(), [](const std::pair<int, int>& a, const std::pair<int, int>& b) { return a.second < b.second; }); ``` 自定义排序 ```C++ // 自定义结构体,用于堆中的元素 struct HeapNode { int value; int index; // 构造函数 HeapNode(int val, int idx) : value(val), index(idx) {} // 为了能够使用标准库的priority_queue,我们需要提供一个比较函数 bool operator>(const HeapNode& other) const { // 小根堆:父节点的值小于子节点的值 return value < other.value; } }; std::priority_queue<HeapNode, std::vector<HeapNode>, std::greater<HeapNode>> min_heap; ``` 那个定义小根堆的是偶 里面是自定义的结构体,怎么设置排序规则 ```c++ struct HeapNode { int value; int index; // 构造函数 HeapNode(int val, int idx) : value(val), index(idx) {} }; // 自定义比较函数,用于小根堆 struct compare { bool operator()(const HeapNode& lhs, const HeapNode& rhs) { // 小根堆:父节点的值小于子节点的值 return lhs.value < rhs.value; } }; // 创建一个小根堆 std::priority_queue<HeapNode, std::vector<HeapNode>, compare> min_heap; ``` 233 ``` //这里填你的代码^^ #include<iostream> #include<cstdio> #include<string> using namespace std; typedef unsigned long long ULL; const int N = 1e5+5,P = 131;//131 13331 ULL h[N],p[N]; ULL query(int l,int r){ return h[r]-h[l-1]*p[r-l+1]; // p[]可以存数值倍数多少次 哈哈哈,ull自动哈希 2*64 ,笑死 } int main(){ int n,m; cin>>n>>m; string s; cin>>s; p[0]=1,h[0]=0; for(int i=0;i<n;i++) { p[i+1]=p[i]*P; h[i+1]=h[i]*P+s[i] ; } while(m--) { int l1,r1,l2,r2; cin>>l1>>r1>>l2>>r2; if(query(l1,r1)==query(l2,r2)) cout<<"Yes"<<endl; else cout<<"No"<<endl; } } ```
C/C++
算法竞赛
赞
博客信息
作者
eeettt123
发布日期
2024-04-13
其他信息 : 其他三字母的人名首字母都是其他同学发布的哦