04 2020 档案

摘要:link class Solution { public: int racecar(int target) { vector<int> dp(target+1); for(int i=1;i<=target;i++){ dp[i]=INT_MAX; int j=1; int m=1; // 先向前走 阅读全文
posted @ 2020-04-30 17:31 feibilun 阅读(111) 评论(0) 推荐(0)
摘要:int main(){ int n; cin>>n; int bit=1; int res=0; while(true){ if(n/bit==0) break; int cur=n/bit%10; int high=n/bit/10; int low=n%bit; if(cur==0){ res+ 阅读全文
posted @ 2020-04-30 10:57 feibilun 阅读(89) 评论(0) 推荐(0)
摘要:link 解法: maxprime存一个数的最大质因数,primeMin[i] 一个数n的质因数存在i,以n结尾所分得的最小子数组数。 class Solution { public: static const int maxn=1000000; int maxprime[maxn+1]; int 阅读全文
posted @ 2020-04-28 18:28 feibilun 阅读(262) 评论(0) 推荐(0)
摘要:class Solution { public: vector<int> singleNumbers(vector<int>& nums) { int total=0; for(int i:nums) total^=i; int one=1; while((one&total)==0) one<<= 阅读全文
posted @ 2020-04-28 10:01 feibilun 阅读(120) 评论(0) 推荐(0)
摘要:link 1.dfs+memo: class Solution { public: int n; int maxJumps(vector<int>& arr, int d) { n=arr.size(); vector<int> memo(n,-1); int res=0; for(int i=0; 阅读全文
posted @ 2020-04-27 16:48 feibilun 阅读(122) 评论(0) 推荐(0)
摘要:link 1. Fenwick Tree: #include <iostream> #include <vector> #include <algorithm> #include <unordered_set> #include <cstring> #include <queue> #include 阅读全文
posted @ 2020-04-27 11:32 feibilun 阅读(100) 评论(0) 推荐(0)
摘要:link 解法: 只需要枚举质数能否整除n。提前筛除sqrt(n)以内的质数,然后到时候只需要枚举这些质数i能否整除n,若能整除,n=n/i;最后n必定是一个质数或是1。 #include <iostream> #include <vector> #include <algorithm> #incl 阅读全文
posted @ 2020-04-26 22:09 feibilun 阅读(111) 评论(0) 推荐(0)
摘要:link using deque: class Solution { public: int constrainedSubsetSum(vector<int>& nums, int k) { int n=nums.size(); int res=nums[0]; deque<int> dq; for 阅读全文
posted @ 2020-04-26 17:03 feibilun 阅读(165) 评论(0) 推荐(0)
摘要:link class Solution { public: int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}}; struct Point{ int x; int y; }; int dis[105][105]; int m,n; Point S,T; int mcn 阅读全文
posted @ 2020-04-25 22:25 feibilun 阅读(243) 评论(0) 推荐(0)
摘要:link #include <iostream> #include <vector> #include <algorithm> #include <unordered_set> #include <cstring> #include <queue> # define LL long long usi 阅读全文
posted @ 2020-04-25 07:52 feibilun 阅读(119) 评论(0) 推荐(0)
摘要:link #include <iostream> #include <vector> #include <algorithm> #include <unordered_set> #include <cstring> #include <queue> # define LL long long usi 阅读全文
posted @ 2020-04-25 07:51 feibilun 阅读(133) 评论(0) 推荐(0)
摘要:link Solution1 归并排序: class Solution { public: int reversePairs(vector<int>& nums) { mergesort(nums,0,nums.size()-1); return res; } int res=0; void mer 阅读全文
posted @ 2020-04-24 12:45 feibilun 阅读(151) 评论(0) 推荐(0)
摘要:link class Solution { public: int getMaxRepetitions(string s1, int n1, string s2, int n2) { int len2=s2.size(); int len1=s1.size(); vector<int> next(l 阅读全文
posted @ 2020-04-19 22:51 feibilun 阅读(91) 评论(0) 推荐(0)
摘要:link class Solution { public: int findMinFibonacciNumbers(int k) { vector<int> fibo; fibo.push_back(1); fibo.push_back(1); while(true){ int i=fibo[fib 阅读全文
posted @ 2020-04-19 17:28 feibilun 阅读(220) 评论(0) 推荐(0)
摘要:link #include <iostream> #define LL long long using namespace std; int N,K; int nextadd[100000]; int val[100000]; int helper(int head){ int cur=head; 阅读全文
posted @ 2020-04-15 21:07 feibilun 阅读(106) 评论(0) 推荐(0)
摘要:link 常规写法: #include <iostream> #include <vector> #include <cstring> #include <stack> #include <unordered_set> #include <queue> #include <cmath> #defin 阅读全文
posted @ 2020-04-14 18:41 feibilun 阅读(184) 评论(0) 推荐(0)
摘要:link class Twitter { public: typedef list<pair<int,int>>::iterator It; unordered_map<int,list<pair<int,int>>> usertotweet; unordered_map<int,unordered 阅读全文
posted @ 2020-04-13 15:31 feibilun 阅读(128) 评论(0) 推荐(0)
摘要:link 解法: 先DFS给每个节点一个id,然后可以获得每个节点这颗子树的区间(一定是连续的),这样就可以进行线段树的操作(单点修改,区间修改,和区间查询), #define LL long long const int maxn=50005; const int mod=1000000007; 阅读全文
posted @ 2020-04-13 11:18 feibilun 阅读(179) 评论(0) 推荐(0)
摘要:link class Solution { public: int N; vector<int> fen; vector<int> processQueries(vector<int>& queries, int m) { N=2*m; fen=vector<int>(2*m+1); vector< 阅读全文
posted @ 2020-04-12 22:13 feibilun 阅读(148) 评论(0) 推荐(0)
摘要:link #include <bits/stdc++.h> # define LL long long using namespace std; int gettime(int hh, int mm, int ss){ return hh*3600+mm*60+ss; } struct Cartim 阅读全文
posted @ 2020-04-07 22:40 feibilun 阅读(143) 评论(0) 推荐(0)
摘要:link Solution1: 自定义变量,union all # Write your MySQL query statement below select username,activity,startDate,endDate from ( select t1.*, @rk:=if(@name= 阅读全文
posted @ 2020-04-06 22:26 feibilun 阅读(278) 评论(0) 推荐(0)
摘要:#include <bits/stdc++.h> # define LL long long using namespace std; int main(){ int N; cin>>N; int mx=0; int idx=0; for(int i=2;i<=sqrt(N);i++){ int t 阅读全文
posted @ 2020-04-06 13:57 feibilun 阅读(115) 评论(0) 推荐(0)
摘要:link 解法: 找离圆心最近的矩形上的点,比较此点到圆心的距离和半径。 class Solution { public: bool checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2 阅读全文
posted @ 2020-04-05 09:35 feibilun 阅读(275) 评论(0) 推荐(0)