随笔分类 -  POJ

摘要:二分一个长度,(count)dis[n]<=k O(PlogNlogK) 1 #include <queue> 2 #include <iostream> 3 using namespace std; 4 const int INF=1e9,N=1e5+10; 5 struct edge { 6 i 阅读全文
posted @ 2021-07-07 10:40 墨鳌 阅读(32) 评论(0) 推荐(0)
摘要:有向图找环 1 #include<cstdio> 2 #include<cstring> 3 int map[27][27],indegree[27],q[27]; 4 int TopoSort(int n){ 5 int t=0,temp[27],p,m,flag=1; //flag=1:有序 f 阅读全文
posted @ 2021-07-01 22:32 墨鳌 阅读(34) 评论(0) 推荐(0)
摘要:题目大意: 有电器和配套的插座,以及每种无限个的装换插头 问:最少多少电器用不上电? 画画图,可以知道是一个二分图,中间结点需要用传递闭包优化掉 Floyd+匈牙利算法(二分图匹配) 1 #include<map> 2 #include<cmath> 3 #include<queue> 4 #inc 阅读全文
posted @ 2021-07-01 22:05 墨鳌 阅读(43) 评论(0) 推荐(0)
摘要:点权拆出来与0号点连边,按照下属→上级的方向建立有向图,跑一个s=0,t=1的单源最短路 限制条件:搜索到的最短路径中,阶级差不超过m 1 #include <queue> 2 #include <vector> 3 #include <cstring> 4 #include <iostream> 阅读全文
posted @ 2021-07-01 17:23 墨鳌 阅读(32) 评论(0) 推荐(0)
摘要:1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 typedef long long ll; 5 const int MAXN=1e5+10; 6 struct node{ll sum,add;}t[MAXN<<2] 阅读全文
posted @ 2020-09-27 17:12 墨鳌 阅读(171) 评论(0) 推荐(0)
摘要:1 #include<cstdio> 2 #include<cstring> 3 int map[27][27],indegree[27],q[27]; 4 int TopoSort(int n){ 5 int t=0,temp[27],p,m,flag=1; //flag=1:有序 flag=-1 阅读全文
posted @ 2020-03-11 17:47 墨鳌 阅读(172) 评论(0) 推荐(0)
摘要:主席树,大家这么叫的,也不知道为什么? 算法思路: 1.先排序,离散化 2.按排名插入n个版本的线段树 3.没有修改,查询即可 由于维护的是权值的区间和, 因此只要查询版本r和l-1,做差比较即可 1 #include <cstdio> 2 #include <algorithm> 3 using 阅读全文
posted @ 2020-02-29 22:22 墨鳌 阅读(198) 评论(0) 推荐(0)
摘要:1 #include <queue> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 int vis[305][305]; 6 int trun[8][2]={{1,2},{2,1},{1,-2},{-2,1},{- 阅读全文
posted @ 2020-02-29 15:02 墨鳌 阅读(213) 评论(0) 推荐(0)
摘要:我不理解为什么写dijkska就WA呢? atoi()是个好东西,给你个颜色,自己体会 疑惑!疑惑!疑惑! 1 #include <queue> 2 #include <cstdio> 3 #include <algorithm> 4 using namespace std; 5 const int 阅读全文
posted @ 2020-02-26 22:18 墨鳌 阅读(137) 评论(0) 推荐(0)
摘要:1 #include <cstdio> 2 struct Matrix{int a[5][5];}; 3 const int N=2,MOD=1e4; 4 Matrix A,B,O,I; 5 Matrix Mul(Matrix A,Matrix B){ 6 Matrix C=O; 7 for(int 阅读全文
posted @ 2020-02-25 20:08 墨鳌 阅读(122) 评论(0) 推荐(0)
摘要:已知矩阵乘法是n^3的,必然超时 故可以在需要验证的等式AB=C两边同时左乘D 一个1xN的任意的不含0矩阵 设E=DA,F=EB,G=DC,则此时只需验证F=G 当匹配到非法列J时,跳出n^2寻找行I即可 记录一下Ans,C[I,J]的正确值,然后就愉快地AC了 为了偷懒,我使用的矩阵是A~G连续 阅读全文
posted @ 2020-02-25 13:07 墨鳌 阅读(235) 评论(0) 推荐(0)
摘要:构造矩阵 1 #include <cstdio> 2 const int MAXN=100; 3 struct Matrix{int a[MAXN][MAXN];}O,I;int N; 4 void OI(int n){N=n;for(int i=0;i<MAXN;i++)for(int j=0;j 阅读全文
posted @ 2020-02-25 10:57 墨鳌 阅读(220) 评论(0) 推荐(0)
摘要:矩阵快速幂,主要是考构造。另外,swap总是写龊? 为什么?干脆放弃了。唉,我太难了。 思路:操作e和s都很好想,主要是g操作 我们可以额外空出一位,记为1,每次要加1,就对这个额外的1进行计算即可 不妨定义A=[1 0 0 ... 0],此时只要构造一组操作的等效矩阵T就好了 就是添一位使初始矩阵 阅读全文
posted @ 2020-02-25 01:14 墨鳌 阅读(185) 评论(0) 推荐(0)
摘要:1 #include <cstdio> 2 typedef long long ll; 3 int quick_pow(ll a,ll b,ll mod){ 4 ll ans=1; 5 for(;b;a=(a*a)%mod,b>>=1)if(b&1)ans=(ans*a)%mod; 6 return 阅读全文
posted @ 2020-02-23 15:30 墨鳌 阅读(172) 评论(0) 推荐(0)
摘要:1 #include <cstdio> 2 const int M=150010,N=30010; 3 struct edge{int v,w,next;}e[M];int head[N],cnt; 4 void add(int u,int v,int w){e[++cnt].v=v,e[cnt]. 阅读全文
posted @ 2020-02-23 15:15 墨鳌 阅读(151) 评论(0) 推荐(0)
摘要:分析:https://www.bilibili.com/read/cv4777102 1 #include <cstdio> 2 #include <algorithm> 3 using namespace std; 4 const int MAXN=1e5+10; 5 struct node{in 阅读全文
posted @ 2020-02-22 20:38 墨鳌 阅读(290) 评论(0) 推荐(0)
摘要:题意就是,找出最长合法子括号序列 容易想到设f[l][r]为l~r的最长合法子括号序列的长度 然后从短的状态往长的状态枚举,不断更新答案就可以了 1 //#include<bits/stdc++.h> 2 #include <cstdio> 3 #include <cstring> 4 #inclu 阅读全文
posted @ 2020-02-21 21:49 墨鳌 阅读(162) 评论(0) 推荐(0)
摘要:每次只能从取集合S中个数的物品,其他和普通Nim游戏相同 预处理出每种物品堆的sg值,然后直接xor一下,xor-sum>0即必胜 1 #include <set> 2 #include <map> 3 #include <cmath> 4 #include <queue> 5 #include < 阅读全文
posted @ 2020-02-20 22:12 墨鳌 阅读(181) 评论(0) 推荐(0)
摘要:题目把Nim游戏为什么可以取异或和讲解得十分清楚,建议多读几次,理解一下 再一个,可以把每次异或视为一次取数,因此(k[i]^sg)<k[i]即为一种可行操作 /* Nim is a 2-player game featuring several piles of stones. Players a 阅读全文
posted @ 2020-02-20 12:21 墨鳌 阅读(157) 评论(0) 推荐(0)
摘要:1 #include <set> 2 #include <map> 3 #include <cmath> 4 #include <queue> 5 #include <vector> 6 #include <cstdio> 7 #include <cstdlib> 8 #include <cstri 阅读全文
posted @ 2020-02-19 21:50 墨鳌 阅读(197) 评论(0) 推荐(0)