函数
1 2 3 4 5
| stl multiset<node> s; multiset<node>::iterator it = s.lower_bound({0, a}); s.erase(it); s.insert({id, data});
|
1 2 3 4 5
| auto it = a.erase(pos, 1) transform(str.begin(), str.end(), str.begin(), ::tolower) c = tolower(c) c = toupper(c) str.compare(0, prefix.length(), prefix) == 0
|
奇葩问题
1 2 3
| printf("%.0f", 3.5); printf("%.1f", 3.15); printf("%.1f", 3.16);
|
一,语法
输入输出: 12:00:00 17:00:00
数据类型 : 5 / 2 5 / 1.0
简单运算: gcd lcm
练习:
1 2 3 4 5 6 7 8 9 10 11 12
| 判断一个数是否为2的n次幂 打印99 乘法表 猜数字 dfs bfs https://codeforces.com/problemset/problem/1873/H Dfs 找最近环点 MEX 循环删除数组中不存在的数 https://codeforces.com/problemset/problem/1872/F 排序完后输出编号 删除k个字符字典序最小https://codeforces.com/contest/1886/problem/C
环每次跳n格,能否遍历完所有点
|
函数+数论+筛质数
B-Basic Gcd Problem_2023牛客国庆集训派对day4 (nowcoder.com)
dp
Problem - E - Codeforces
二,算法入门
helloWorld题单
vector sort queue string 队列
C-小红的数字拆解_牛客周赛 Round 34 (nowcoder.com)
队列
D-小红的陡峭值_牛客周赛 Round 34 (nowcoder.com)
二分查找
- 在有序数组中查找元素的下标
- 查找
dfs(递归) 基础:
一, 树
- 求每个节点的深度
- 求每个子树的节点个数
- 求根节点到子节点的最小路径
Problem - 1882D - Codeforces
dfs 167. 木棒 - AcWing题库
二,图
- 环
位运算
异或 |
按位和 |
按位与 |
左右移 |
^ |
& |
| |
<< >> |
异或俗称: 无进位加法
a ^ b = x => a ^ x =b a ^ 1 = !a a ^ 0 = a
- 二进制枚举
- 求2的幂
- st表
- 判断二进制中某位是0还是1
Problem - 1879D - Codeforces
判断一个数是否为2的n次幂
- 二进制位只有一个1
- 除2,模2
- 列出所有2的幂
例: 求l~r区间 5的倍数或3的倍数的数的个数
dp[r] - dp[l-1]
因数
位运算
问题 - C - 代码强制 (codeforces.com)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #include<bits/stdc++.h> #define int long long using namespace std; const int N = 100010; int f[N]; void solve() { string s; cin >> s; int num = 0, c1 = 1, c2 = 1e9+1, flag = 0; for(int i = 0; i < s.size(); i++) { if(s[i]=='+') num++; else if(s[i]=='-') { c1 = min(c1, --num); if(num < c2) c2 = 1e9+1; } else if(s[i]=='1') { if(c2 <= num) {flag = 0, break;} c1 = num; } else if(s[i]=='0') { if(num < 2 || c1 >= num) {flag = 0, break;} c2 = min(c2, num); } } cout << (flag ? "YES" : "NO") << endl; } signed main() { int T; cin >> T; while(T--) solve(); }
|
Problem - E - Codeforces
st表 & 按位与
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #include<bits/stdc++.h> #define int long long using namespace std; const int N = 200010; int f[N][30]; int check(int l, int r) { int k = log2(r - l + 1); return f[l][k] & f[r - (1<<k) + 1][k]; } void solve() { int n; cin >> n; for(int i = 1; i <= n; i++) cin >> f[i][0]; for(int i = 1; i <= 20; i++) for(int j = 1; j + (1 << (i-1)) <= n; j++) f[j][i] = f[j][i-1] & f[j + (1 << (i-1))][i-1]; int q; cin >> q; while(q--) { int fr, x; cin >> fr >> x; int l = fr, r = n; while(l < r) { int mid = l + r + 1 >> 1; if(check(fr, mid) >= x) l = mid; else r = mid - 1; } if(l == fr && f[l][0]<x) cout << -1 << " "; else cout << l << " "; } puts(""); } signed main() { int T; cin >> T; while(T--) solve(); }
|