2022年10月14日
摘要: 并查集路径压缩中,维护某节点到根节点的距离(依题意为abs(x-y)%1000) 即 d[i] +=d[father[i] ] #include <iostream> #include <algorithm> #include <cmath> using namespace std; const i 阅读全文
posted @ 2022-10-14 13:34 towboat 阅读(16) 评论(0) 推荐(0)
摘要: 并查集判断图上是否有环 #include <iostream> #include <algorithm> using namespace std; const int N=1e5+4; int fa[N]; int find(int x){ return x==fa[x]?x:fa[x]=find( 阅读全文
posted @ 2022-10-14 13:05 towboat 阅读(8) 评论(0) 推荐(0)
摘要: 人跨台阶,每次能跨越的高度最大为D,给了每个台阶的高度,求最多走多高 解: 求一个数组里第一个x , a[x]>D ?处理一个前缀max ,然后查找 #include <iostream> #include <algorithm> using namespace std; const int N=2 阅读全文
posted @ 2022-10-14 08:31 towboat 阅读(22) 评论(0) 推荐(0)
  2022年10月13日
摘要: 题目 There are nn chests. The ii-th chest contains aiai coins. You need to open all nn chests in order from chest 11 to chest nn. There are two types of 阅读全文
posted @ 2022-10-13 17:02 towboat 阅读(15) 评论(0) 推荐(0)
摘要: const int M=1e3; const int N=2e3; int c[N][N]; void init(){ int i,j; c[1][1]=1; for(i=0;i<=M;i++) c[i][0]=1; for(i=2;i<=M;i++) for(j=1;j<=i;j++) c[i][ 阅读全文
posted @ 2022-10-13 11:16 towboat 阅读(26) 评论(0) 推荐(0)
摘要: 全概率公式 #include <iostream> #include <cstring> #include <iomanip> using namespace std; int main(){ double a,b,c; while(cin>>a>>b>>c){ cout<<setprecision 阅读全文
posted @ 2022-10-13 10:53 towboat 阅读(12) 评论(0) 推荐(0)
  2022年10月12日
摘要: 求解 ax Ξb (mod n) 充要条件: ax-b= k*n 即 ax-ny = b 1. 用exgcd 可以求方程 ax-ny= gcd(a,n) 的一组解 即 x0 , y0, https://www.cnblogs.com/towboa/p/17001472.html 2. 可以得到原方程 阅读全文
posted @ 2022-10-12 23:53 towboat 阅读(23) 评论(0) 推荐(0)
摘要: 运用分治,复杂度logn typedef long long LL; LL mod; LL f(LL a,LL b){ if(b==1) return a; if(b==0) return 1; LL t=f(a,b/2); return b%2==0? t*t%mod : (((t*t)%mod) 阅读全文
posted @ 2022-10-12 23:31 towboat 阅读(16) 评论(0) 推荐(0)
摘要: int b[N+2], pm[N+2],tot=0; void init(){ b[1]=1; for(int i=2;i<=N;i++){ if(b[i]) continue; pm[++tot]= i; for(int j=2;j*i<=N;j++) b[j*i]=1; } } const in 阅读全文
posted @ 2022-10-12 23:16 towboat 阅读(24) 评论(0) 推荐(0)
摘要: 算法求解了不定方程 ax+by=gcd(a,b) (1) 的一组解x0,y0 void gcd(int a,int b,int &d,int &x,int &y){ if(b==0){ d=a; x=1,y=0; return ; } gcd(b,a%b,d,y,x); y-=x*(a/b); } 阅读全文
posted @ 2022-10-12 23:05 towboat 阅读(22) 评论(0) 推荐(0)