上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 13 下一页
摘要: 求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) 编辑
摘要: 题目链接:幸运数字Ⅱ 打表: #include<bits/stdc++.h> using namespace std; typedef long long ll; ll l,r,j,ans,pos; ll k[10005],g; void dfs(ll x) { if(x>4444444444) r 阅读全文
posted @ 2020-06-27 14:46 chstor 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 题目链接:走出迷宫 DFS解法: #include<bits/stdc++.h> using namespace std; const int maxn=510; int n,m,s1,s2,t1,t2; char mp[maxn][maxn]; int vis[maxn][maxn]; int d 阅读全文
posted @ 2020-06-27 11:21 chstor 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 搜索 • 通过不停的试探去寻找解的一种算法。 • 与其说是一种算法,不如说是一种方法。 • 基础的方法有暴力的搜索法,深搜,广搜三种。 • 更高级的有IDDFS,DBFS,A*,IDA*等等 深度优先搜索(dfs) “一条道走到黑”“走不了了再倒回去” 算法过程: VOID DFS(状态 A) 1. 阅读全文
posted @ 2020-06-27 11:17 chstor 阅读(120) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 13 下一页