首页 > 其他分享 >一些神奇の小公式&板子

一些神奇の小公式&板子

时间:2024-01-24 10:24:45浏览次数:18  
标签:node head idx int 公式 ll 板子 include 神奇

一些神奇の小公式

  • $n$ 以内的质数个数为 :

    ​ $n/\log n*\sqrt{n}$

  • $n$ 个点的距离平方和:

    ​ $n*(\sum x_i+\sum y_i)-[(\sum x_i)^2+(\sum y_i)^2]$

一些神奇の板子

万年不变

万能(火车)头

#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<string>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll; 
const int N,M,INF=1e9,MIN=-1e9,mo;

图论板子

链式前向星

struct no{
    int to,v;
}node[M];
int head[N],idx=0;
void add(int u,int v){
    idx++;
    node[idx].v=v;
    node[idx].to=head[u];
    head[u]=idx;
}

并查集

int f[N];
void init(int n){
    for(int i=1;i<=n;i++)
    f[i]=i;
    return;
}
int find(int u){
    if(f[u]!=u)
    f[u]=find(f[u]);
    return f[u];
}
void hb(int u,int v){
    int fu=find(u),fv=find(v);
    if(fu!=fv){
        f[fv]=fu;
    }
    return;
}

$dinic$ 算法

需定义 $n$ , $S$ , $T$

struct no{
	int v,to,f;
}node[M];
int head[N],idx=1;
void add(int u,int v,int f){
	idx++;
	node[idx].v=v;
	node[idx].f=f;
	node[idx].to=head[u];
	head[u]=idx;
	idx++;
	node[idx].v=u;
	node[idx].f=0;
	node[idx].to=head[v];
	head[v]=idx;
	return;
}
int q[N],d[N],cur[N];
bool bfs(){
	memset(d,-1,sizeof(d));
	int h=0,t=0;
	q[0]=S,d[S]=0;
	cur[S]=head[S];
	while(h<=t){
		int u=q[h++];
		for(int i=head[u];i;i=node[i].to){
			int v=node[i].v;
			if(d[v]==-1&&node[i].f){
				d[v]=d[u]+1;
				if(v==T)
				return 1;
				cur[v]=head[v];
				q[++t]=v;
			}
		}
	}
	return 0;
}
int find(int u,int limit){
	if(u==T)
	return limit;
	int flow=0;
	for(int i=cur[u];i&&flow<limit;i=node[i].to){
		int v=node[i].v;
		cur[u]=i;
		if(d[v]==d[u]+1&&node[i].f){
			int t=find(v,min(node[i].f,limit-flow));
			if(!t)
			d[v]=-1;
			node[i].f-=t;
			node[i^1].f+=t;
			flow+=t;
		}
	}
	return flow;
}
int dinic(){
	int r=0,flow;
	while(bfs()){
		while(flow=find(S,INF))
		r+=flow;
	}
	return r;
}

数论板子

$kasumi$ (快速幂)

ll POW(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
        res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}

辗转相除 $gcd$

ll gcd(ll x,ll y){
	ll r=x%y;
	while(r){
		x=y;
		y=r;
		r=x%y;
	}
	return y;
}

优化时间板子

快读

ll read(){
    ll res=0,f=1;
    char _z=getchar();
    while(_z<'0'||_z>'9'){
        if(_z=='-')
        break;
        _z=getchar();
    }
    if(_z=='-'){
        _z=getchar();
        f=-1;
    }
    while(_z>='0'&&_z<='9'){
        res=(res<<3)+(res<<1)+_z-'0';
        _z=getchar();
    }
    return res*f;
}

快输

void putout(ll x){
    if(x>9)
    putout(x/10);
    putchar(x%10+'0');
    return;
}

树状数组

int n;		//数的个数 
int c[N];	//前缀和 
int lowbit(int x){
	return x&-x;
}
void add(int x,int y){	//在x的位置加上y 
	for(int i=x;i<=n;i+=lowbit(i)){
		c[i]+=y;
	}
	return;
}
int qu(int x){	//查询[1,x]的数的和 
	int res=0;
	for(int i=x;i>0;i-=lowbit(i)){
		res+=c[i];
	}
	return res;
}

标签:node,head,idx,int,公式,ll,板子,include,神奇
From: https://www.cnblogs.com/liuqichen121/p/17984019

相关文章

  • 板子集合
    tarjan点击查看代码//缩点voidtarjan(intu){dfn[u]=low[u]=++t;s[++top]=u;vis[u]=1;for(inti=0;i<g[u].size();++i){intv=g[u][i];if(!dfn[v]){tarjan(v);low[u]=min(low[u],low[v]);}elseif(vis[v])low[u]=......
  • 【动画进阶】神奇的 3D 卡片反光闪烁动效
    最近,有群里在群里发了这么一个非常有意思的卡片Hover动效,来源于此网站--key-drop,效果如下:非常有意思酷炫的效果。而本文,我们不会完全还原此效果,而是基于此效果,尝试去制作这么一个类似的卡片交互效果:该效果的几个核心点:卡片的3D旋转跟随鼠标移动效果如何让卡片在Hove......
  • 常用 $ \LaTeX $ 数学公式(持续更新)
    Updateon2022.11.12:修正了一处小错误希望这份东西能尽量帮助大家,节省在\(\LaTeX\)公式大全中寻找的时间,欢迎在评论区提出建议。如果您有需求,例如添加某一部分的公式,可私信号主。插入公式$你要插入的公式$这是普通插入(即紧跟随文字插入)$$你要插入的公式(最好是比较大的)$$......
  • 一些多项式常用操作的公式推导
    怕我以后忘记了看不懂自己的板子(((牛顿迭代用于求解函数零点的近似值。设函数\(f(x)\)的零点近似值为\(x_0\),过点\((x_0,f(x_0))\)作\(f(x)\)的切线,切线与\(x\)轴交点的横坐标即为新的近似值。切线解析式为\(y=f'(x_0)(x-x_0)+f(x_0)\),当\(y=0\)时\(x=x_0-\dfrac{f......
  • 22. 从零用Rust编写正反向代理,一个数据包的神奇HTTP历险记!
    wmproxywmproxy已用Rust实现http/https代理,socks5代理,反向代理,静态文件服务器,四层TCP/UDP转发,内网穿透,后续将实现websocket代理等,会将实现过程分享出来,感兴趣的可以一起造个轮子项目地址国内:https://gitee.com/tickbh/wmproxygithub:https://github.com/tickbh/wmproxy数......
  • 如何使用Java在Excel中添加动态数组公式?
    本文由葡萄城技术团队发布。转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具、解决方案和服务,赋能开发者。前言动态数组公式是Excel引入的一项重要功能,它将Excel分为两种风格:Excel365和传统Excel(2019或更早版本)。动态数组功能允许用户从单个单元格中的公式......
  • 2d物理引擎学习 - 基于约束的公式解决接触稳定性问题
    先看下直接用弹性碰撞的公式,会出现的问题:Box落在地面上后,没有停在地面上,而是还在不断的下沉。弹性碰撞公式处理碰撞后弹开没有大问题,但是处理物体碰撞后的接触存在不稳定问题。 如何解决?目前物理引擎最主流的解决方法是:基于约束来组织物理公式,而不是直接套用物理公式。什......
  • 一段神奇的代码
    importtimeimportosimportpsutilimportntplibfromdatetimeimportdatetimedefget_network_time():ntp_client=ntplib.NTPClient()response=ntp_client.request('pool.ntp.org')returndatetime.fromtimestamp(response.tx_time)d......
  • 三角形中的三角公式
    ......
  • 三角形中的三角公式
    前言在三角函数章节中,我们学习了许多公式,比如同角三角函数关系,诱导公式,和角公式,差角公式,二倍角公式,半角公式等;当这些角放置到三角形中,由于有了内角和的限定等,所以它们又有了不同的外在形式;编辑中。。。三角形内角和\(A+B+C=\pi\),\(A+B=\pi-C\),\(\cfrac{A+B}{2}=\cfrac{\pi}{......