05 2019 档案
摘要:割点: void tarjan(int u){ dfn[u]=low[u]=++cnt; int flag=0; for(int i=head[u];~i;i=e[i].nextt){ int v=e[i].v; if(!dfn[v]){ tarjan(v); low[u]=min(low[u],l
阅读全文
摘要:建超级s向每个食物连容量为1的边,超级汇点t; 每个饮料向t连容量为1的边,将每头牛拆点,一个连该牛喜欢的食物,另一点连该牛喜欢的饮料,俩个点相连,容量均为1; ans=跑一遍最大流 #include<iostream> #include<cstring> #include<cstdio> #inc
阅读全文
摘要:学习资料:https://www.cnblogs.com/shadowland/p/5872257.html 板子: void tarjan(int u){ dfn[u]=low[u]=++cnt; sta[++top]=u; vis[u]=true; for(int i=0;i<g[u].size
阅读全文
摘要:#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<queue> using namespace std; typedef long long ll; inline int read()
阅读全文
摘要:把该图的无向边随便定向,计算每个点的入度和出度。如果有某个点出入度之差为奇数,那么肯定不存在欧拉回路。因为欧拉回路要求每点入度 = 出度,也就是总度数为偶数,存在奇数度点必不能有欧拉回路; 好了,现在每个点入度和出度之差均为偶数。那么将这个偶数除以2,得x。也就是说,对于每一个点,只要将x条边改变方
阅读全文
摘要:1,从各个顾客到汇点各有一条边,容量就是各个顾客能买的数量上限。 2,在某一轮中,从该顾客打开的所有猪圈都有一条边连向该顾客,容量都是∞。 3,最后一轮除外,从每一轮的i号猪圈都有一条边连向下一轮的i号猪圈,容量都是∞,表示这一轮剩下的猪可以留到下一轮。 4,最后一轮除外,从每一轮被打开的所有猪圈,
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3507 解释:当且仅当g【j,k】程璐,j对dp【i】的更新由于k对dp【i】的; 解释:对于第2点,因为单调队列维护的要是斜率上升的数据结构;所以要做此循环 对于第3点,因为是斜率上升的数据结构,所以如果满足持续
阅读全文
摘要:hdu1285 http://acm.hdu.edu.cn/showproblem.php?pid=1285 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #inc
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; const int M=3e5+5; struct node{ int l,r,cnt,lazy; node(int l1=0,int r1=0,int cnt1=0,int lazy1=0):l(l1),r(
阅读全文
摘要:网1:飞行员匹配 题目链接:https://www.oj.swust.edu.cn/problem/show/1736 俩种做法: /**********二分图匹配做法***********/ #include<bits/stdc++.h> using namespace std; const in
阅读全文
摘要:bool spfa(){ queueque; que.push(s); memset(dis,INF,sizeof(dis)); dis[s]=0; while(!que.empty()){ int u=que.front(); que.pop(); vis[u]=0; for(int i=head[u];~i;i=edge[i].nextt){ int v=ed...
阅读全文
摘要:bool bfs(){ memset(deep,0,sizeof(deep)); queueque; que.push(s); deep[s]=1; while(!que.empty()){ int u=que.front(); que.pop(); for(int i=head[u];i!=-1;i=e[i].nextt){ int v=e[i].v; if(...
阅读全文
摘要:https://acm.ecnu.edu.cn/contest/173/problem/E/ 区间操作,线段树; 维护乘的次数和除的次数 最后答案是,div和mul共同作用的结果, 分两种来考虑,第一种是当前有足够多次1操作,所以当再来一次操作时,直接在此基础上进行修改,除就减,乘就加; 第二种比较
阅读全文
摘要:https://acm.ecnu.edu.cn/contest/173/problem/C/ 联通块染色,若i,j满足题目中的条件,那么他们在每幅图中的染色情况相同,即hash值相同 使用unsigned long long hash 自动对2^64取模;
阅读全文
摘要:https://www.luogu.org/problemnew/show/P3369 #include<bits/stdc++.h> using namespace std; inline int read(){ int sum=0,x=1; char ch=getchar(); while(ch
阅读全文
摘要:莫队+重点轻点 题意:给你n个点(每个点都有一个颜色,0代表黑色,1代表白色),m条边,每条边有一个权值.现在有有两个操作,一个是修改某个点的颜色(白变成黑/黑变成白),另外一个是询问那些边的两个端点都为指定颜色的权值总和 分析:将所有点分为重点和轻点,但是这次重点和重点之前的边要建在一个图中,剩余
阅读全文
摘要:https://www.luogu.org/problemnew/show/P1494 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int M=5e4+4; 5 struct nod
阅读全文
摘要:二维坐标离散化 离散化的思想就是将分布大却数量少(即稀疏)的数据进行集中化的处理,这样可以有利于程序的空间与时间,能减少遍历次数与空间储存。 思想理解起来其实道理很简单,如坐标(3,2000),(10005,31),(10006,5)离散至新图,先看x坐标,3个点有3,10005,10006,离散后
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 inline int read(){ 4 int sum=0,x=1; 5 char ch=getchar(); 6 while(ch<'0'||ch>'9'){ 7 if(ch=='-') 8 x
阅读全文
摘要:1 const int N = 1e5 + 5; 2 vector<int> g[N]; 3 int fa[N], dp[N], sz[N], son[N], top[N], dfn[N], to[N], cnt = 0, n; 4 void dfs1(int u, int o) { 5 fa[u]
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 const int M=3e5+5; 4 struct node{ 5 int l,r,cnt,lazy; 6 node(int l1=0,int r1=0,int cnt1=0,int lazy1
阅读全文
摘要:在写的时候加了判断询问位置先后的swap结果wa了快十次了,不知道为什么; http://acm.hdu.edu.cn/showproblem.php?pid=1754
阅读全文
摘要:不开longlong见祖宗 题目没说操作中的a,b大小要注意 接着就是状压+线段树 http://poj.org/problem?id=2777
阅读全文
摘要:区间修改&&单点查询(树状数组) #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<vector> #include<list> #include<ma
阅读全文
摘要:树的直径: 利用了树的直径的一个性质:距某个点最远的叶子节点一定是树的某一条直径的端点。 先从任意一顶点a出发,bfs找到离它最远的一个叶子顶点b,然后再从b出发bfs找到离b最远的顶点c,那么b和c之间的距离就是树的直径。 用dfs也可以。 http://poj.org/problem?id=19
阅读全文
摘要:图不一定联通,所以用并查集找各个联通块的祖先分别建图,之后就和LCA的步骤差不多了
阅读全文
摘要:在dfs的过程中维护三个数组: deep[i],表示i点在树中的深度; grand[x][i],表示x的第2^i个祖先的节点编号; dis[x][i],表示x到它2^i祖 先的距离。
阅读全文
摘要:题:http://acm.hdu.edu.cn/showproblem.php?pid=6126 题意:题目给出n,m,k 然后给出n*m的矩阵a[i][j]代表第i个人在获得j 颗糖果能得到的满足值; k行[x,y,z]表示第x个人的糖果减去第y个人的糖果需要不大于z。 分析: 因为题目的z可能为
阅读全文
摘要:考虑到树上操作;首先题目要我们求每条路径上出现不同颜色的数量,并把所有加起来得到答案;我们知道俩俩点之间会形成一条路径,所以我们可以知道每个样例的总的路径的数目为:n*(n-1)/2; 这样单单的求,每条路径(n:2e5)无疑会爆; 这样我们假设所有路径上都存在所有的颜色,所有总的答案为n*(n-1
阅读全文