12 2021 档案
摘要:1 class Solution { 2 public: 3 int lastRemaining(int n, int m) { 4 if(n==1)return 0; 5 return (m%n+lastRemaining(n-1,m))%n;//以m%n为参考系,当成0,求得n-1的解再换系;也
阅读全文
摘要:1 const int N=1e5+5; 2 class Solution { 3 public: 4 int ch[N][26]; 5 vector<string> findAllConcatenatedWordsInADict(vector<string>& words) { 6 unorder
阅读全文
摘要:1 class Solution { 2 public: 3 const int N=1e5+5; 4 vector<long long> getDistances(vector<int>& arr) { 5 int n=arr.size(); 6 vector<int>v[N]; 7 vector
阅读全文
摘要:1 class Solution { 2 public: 3 vector<int> recoverArray(vector<int>& nums) { 4 multiset<int>s; 5 int n=nums.size(); 6 sort(nums.begin(),nums.end()); 7
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e3+5; 4 int px[N],py[N],x[N],y[N],r[N]; 5 bitset<N>bt[N],t; 6 long long pow_x(int x) 7
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int main() 5 { 6 int n,ans=0; 7 cin>>n; 8 for(int i=1;i<=(1<<9);i++)//10位数,考虑每位取0.1转成2进制表示 9 { 10
阅读全文
摘要:x ≡a1(mod m1)x ≡a2(mod m2)x ≡a3(mod m3)中国剩余定理 x在模m1*...*mn下有唯一解; 其中m1,m2,m3两两互质 M=Πmi;Mi=M/mi;其中 Miyi ≡1(mod m1) ,即yi是Mi模mi的逆; 答案 x=∑aiMiyi 正确性:对于任意 同
阅读全文
摘要:leetcode 1044. 最长重复子串 1 typedef unsigned long long ull; 2 const int N=3e4+5; 3 const int mod=1e9+7; 4 const int p=131;//这个取值很重要,17,19都被这题卡了; 5 ull px[
阅读全文
摘要:1 a*b=lcm[a,b]*gcd(a,b); 2 证明: 3 令lcm[a,b]=c=ab/(a,b); 4 因为a|c , b|c,所以c为a,b的公倍数,所以[a,b]|c; 5 由裴蜀定理 6 存在x,y使得 7 ax+by=(a,b); 8 ax/(a,b)+by/(a,b)=1; 9
阅读全文
摘要:1 1.gcd(a,b)=gcd(b,a-nb);默认a>=b; 2 设gcd(a,b)=d,gcd(b,a-nb)=k; 3 k|b,k|a-nb;-->k|a 4 即k为a,b的公因数则k|d; 5 又因为d|b,d|a ,所以d|a-nb;所以 d|k-->k=d; 6 又因为当n=q时,a-
阅读全文
摘要:洛谷P1082 [NOIP2012 提高组] 同余方程 这题不能用费马小定理,b不一定是质数,求逆元是能满足互质条件,但是费马小定理还需要b是质数; 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4
阅读全文
摘要:洛谷P1082 [NOIP2012 提高组] 同余方程 这题费马小定理肯定不行,费马小定理的前提是p为质数,gcd(a,p)=1,即互质;所以我们只能考虑拓展欧几里得 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long lo
阅读全文
摘要:P1601 A+B Problem(高精) 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=505; 4 int a[N],b[N],c[N]; 5 void get(string &s,int *p) 6 { 7 int
阅读全文
摘要:1 class Solution { 2 public: 3 long long getDescentPeriods(vector<int>& prices) { 4 int n=prices.size(); 5 long long dp[n+1]; 6 for(int i=1;i<=n;i++)d
阅读全文
摘要:1 class Solution { 2 3 public: 4 int kIncreasing(vector<int>& arr, int k) { 5 int n=arr.size(); 6 int st[n],top=0,ans=0,cnt=0; 7 for(int i=0;i<k;i++)
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 int a,b; 4 int gd; 5 vector<int>v; 6 int main() 7 { 8 9 cin>>a>>b; 10 int n; 11 cin>>n; 12 gd=gcd(a
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e6+5; 4 int dp[N];//dp[i]表示以i结尾的最长合法串长度; dp[i]转移,考虑当前i为')' 栈里只压入'('则dp[i]=dp[j-1]+i-j+
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=105; 4 int n; 5 int in[N]; 6 vector<int>G[N]; 7 int main() 8 { 9 scanf("%d",&n); 10 que
阅读全文
摘要:P1546 [USACO3.1]最短网络 Agri-Net 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=105; 4 int n,tot; 5 int fa[N]; 6 int read() 7 { 8 int x=0
阅读全文
摘要:题目后续补吧,主要解决问题; 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+5; 4 int fa[N]; 5 int find_fa(int x){ 6 return fa[x]=(x==fa[x])?x:fi
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e2+5; 4 int G[N][N]; 5 int main() 6 { 7 int n,m; 8 scanf("%d%d",&n,&m); 9 for(int i=1;
阅读全文
摘要:1610. 可见点的最大数目 1 class Solution { 2 public: 3 const double pi=M_PI; 4 double get_angel(int x1,int y1,int x2,int y2) 5 { 6 return atan(1.0*(y2-y1)/(x2-
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef pair<int,double>pii; 4 const int N=2005; 5 const double inf=1e-5; 6 int n,m,st,ed; 7 double
阅读全文
摘要:题目要求的是两个牧场的最小直径,数据给出不只是两个独立牧场而是至少两个 所以我们要去暴力枚举每个不属于同一牧场的直径的最小值 这里需要注意的是两个牧场连起来的直径不一定是连线后 i所在的最短路+j所在的最短路+dis(i,j); 例如 1 #include<bits/stdc++.h> 2 usin
阅读全文
摘要://这是一道一笔画问题 算法名字叫Hierholzer 算法 算法介绍传送门https://www.cnblogs.com/acxblog/p/7390301.html 1 class Solution { 2 public: 3 vector<vector<int>> validArrangeme
阅读全文
摘要:630. 课程表 III 这题的思路是贪心; 首先对于一个课程,[d1,ed1],[d2,ed2];如果都能满足要求,我们优先选择ed小的;这里假设ed1<ed2; 证明:如果ed2选上能获得最优解,那么ed2的课程换成ed1一定不比最优解差,所以按照结束时间ed排序; 问题在于当dx+time>e
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 int len; 4 int myheap[12]; 5 //堆排序每个子节点最多交换log次,所以堆排是nlogn; 6 void put(int x) 7 { 8 myheap[++len]=x
阅读全文
摘要:2106. 摘水果 1 const int N=2e6; 2 int lt[N],rt[N]; 3 class Solution { 4 public: 5 int maxTotalFruits(vector<vector<int>>& fruits, int startPos, int k) {
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 map<ll,int>mp; 5 const int N=1e6; 6 ll ans[N]; 7 int main() 8 { 9 int m; 10
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef pair<int,int> pii; 5 const int N=1e6; 6 int path[N]; 7 ll dis[N]; 8
阅读全文
摘要:洛谷 P6218 [USACO06NOV] Round Numbers S 1 #include<bits/stdc++.h> 2 using namespace std; 3 //dp[dep][cnt1][cnt0];//表示1-n中考虑到dep位,1的个数为cnt1个,0的个数为cnt0个,的
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 struct node{ 4 node *left,*right; 5 int val; 6 }; 7 void insert(node * &bt,int n) 8 { 9 10 if(bt) 1
阅读全文
摘要:洛谷P4127 [AHOI2009]同类分布 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 ll dp[20][163][163];//表示余数和为md,考虑到dep位第dep位还未选,数位和为s
阅读全文
摘要:1 class Solution { 2 public: 3 typedef pair<int,int> pii; 4 struct cmp{ 5 bool operator ()(pii &a,pii &b) 6 { 7 return a.second>b.second; 8 } 9 }; 10
阅读全文
摘要:ACWing 1133. 第二短路 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef pair<int,int> pii; 4 const int N=1e5+5; 5 int dis1[N],dis2[N],ans=INT_MAX
阅读全文
摘要:leetcode 144. 二叉树的前序遍历 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * Tr
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=105; 4 int dis[N][N]; 5 int val[N]; 6 int n; 7 int main() 8 { 9 memset(dis,0x3f,sizeof(
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+5; 4 /*int ph,pt;//head tail; 5 int myq[20];//ph==pt队列为空; 6 //当进行了pop操作Ph会前移,造成空间浪费
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 string t[100]; 4 int tot=0; 5 int to_num(string &s) 6 { 7 int x=0,f=1; 8 for(auto &p:s) 9 { 10 if(p
阅读全文
摘要:1 #include<bits/stdc++.h> 2 #define mytest 3 using namespace std; 4 const int N=1e5+5; 5 const int mod=1337; 6 int h[N];//h[i]表示key为i的开头节点编号 7 int tot
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 char st[33],top; 4 int change_ten(int d) 5 { 6 int x=0; 7 for(int i=1;i<=top;i++) 8 { 9 if(st[i]>='
阅读全文
摘要:day 6. 类的权限 class mydata { public: void get(int x) { i=x; cout<<i<<endl; } private:int i;//默认私有 } ; int main() { mydata d1; d1.i=1;//这里是禁止访问的,因为i是私有成员
阅读全文
摘要:day 5. 引用的本质是指针实现的,所有类型的指针都是四字节; 右值引用也能改变内存实体 int main() { int a(4); int && numr(move(a));//a是左值,移动语义把左值变右值 numr=1; cout<<numr<<" "<<a<<endl;//都是1,右值引
阅读全文
摘要:day4 可变参数模板 #include<cstdarg> tempate<typename T,typename...Args> // #include<bits/stdc++.h>using namespace std; void show(){//递归结束需要的程序,相当于重载 }templa
阅读全文
摘要:day 3.mutable需要注意的是:mutable不能修饰const 和 static 类型的变量。我们知道,被const关键字修饰的函数的一个重要作用就是为了能够保护类中的成员变量。即:该函数可以使用类中的所有成员变量,但是不能修改他们的值。然而,在某些特殊情况下,我们还是需要在const函数
阅读全文
摘要:构造函数 用途:用来初始化类对象的数据成员; 构造函数和类名相同,没有返回值,可以有多个构造函数 不同的构造函数形参数量或者类型要有所区别 构造函数不能声明成const,因为构造函数要对数据成员进行赋值,而且类对象获得const属性是在构造函数完成之后 默认构造函数没有任何参数,如果我们没有声明任何
阅读全文