摘要: 区间合并 ①按区间左端点排序 ②维护一个基准(st-ed) // 将所有存在交集的区间合并 void merge(vector<PII> &segs) { vector<PII> res; sort(segs.begin(), segs.end()); int st = -2e9, ed = -2e 阅读全文
posted @ 2020-07-02 13:40 chstor 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 求n的第k位数字 ①先把第k位移到最后一位n>>k ②看个位是几 x&1 综合:n>>k&1 n>>k&1 返回n的最后一位1 lowbit(n): n&-n 阅读全文
posted @ 2020-07-02 13:38 chstor 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 朴素做法:O(n^2) for(int i=0;i<n;i++) for(int j=0;j<=i;j++) if(check(j,i)){ res=max(res,i-j+1); } 双指针算法:O(n) for(int i=0;i<n;i++) { while(j<=i&&check(j,i)) 阅读全文
posted @ 2020-07-02 12:07 chstor 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 高精度加法 // C = A + B, A >= 0, B >= 0 #include<iostream> #include<vector> using namespace std; vector<int > add(vector<int > &A, vector<int > &B) { vecto 阅读全文
posted @ 2020-07-02 12:02 chstor 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 790. 数的三次方根 #include<iostream> using namespace std; int main() { double x; cin>>x; if(x<0) { cout<<"-"; x=-x; } double l=0,r=x; while(r-l>1e-8) { doub 阅读全文
posted @ 2020-07-02 11:54 chstor 阅读(263) 评论(0) 推荐(0) 编辑
摘要: 789. 数的范围 #include<iostream> #include<vector> #include<algorithm> using namespace std; const int maxn =1e5+10; int a[maxn]; int main() { int n,m,x; ci 阅读全文
posted @ 2020-07-02 11:52 chstor 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 整数二分 转载自ACwing bool check(int x) {/* ... */} // 检查x是否满足某种性质 // 区间[l, r]被划分成[l, mid]和[mid + 1, r]时使用: int bsearch_1(int l, int r) { while (l < r) { int 阅读全文
posted @ 2020-07-02 11:51 chstor 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 快速排序 分治 ①确定分界点:q[l],q[(l+r)/2],q[r] ②调整范围 ③递归处理左右两段 #include<iostream> using namespace std; const int N = 1e5+10; int n; int a[N]; void quick_sort(int 阅读全文
posted @ 2020-07-02 11:45 chstor 阅读(95) 评论(0) 推荐(0) 编辑