Luogu P11158 【MX-X6-T4】夢重力 题解】的更多相关文章

luogu P1549 棋盘问题(2) 题解 题目描述 在\(N * N\)的棋盘上\((1≤N≤10)\),填入\(1,2,-,N^2\)共\(N^2\)个数,使得任意两个相邻的数之和为素数. 例如:当\(N=2\)时,有: 其相邻数的和为素数的有: \(1+2,1+4,4+3,2+3\) 当\(N=4\)时,一种可以填写的方案如下: 在这里我们约定:左上角的格子里必须填数字\(1\). 输入输出格式 输入格式: 一个数\(N\) 输出格式: 如有多种解,则输出第一行.第一列之和为最小的排列方…
题目链接:https://www.luogu.org/problemnew/show/P2590 我想学树剖QAQ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 31000; int fa[maxn], dep[maxn], size[maxn], son[maxn], to…
题目链接:https://www.luogu.org/problemnew/show/P2279 想怎么贪怎么贪 #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 1010; int n, ans, dis[maxn], dep[ma…
题目链接:https://www.luogu.org/problemnew/show/P2762 算是拍照那个题的加强下. 输入真的很毒瘤.(都这么说但好像我的过了?) #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define ll long long using namespace std; con…
题目链接:https://www.luogu.org/problemnew/show/P2947 因为在单调队列上被dalao们锤爆 怒刷单调队列题 何为单调队列? 设我们的队列为从左至右单调递增 对于样例数据 3 2 6 1 1 2 我们先把3入队 此时队列:3 再将2从后面入队 此时队列:2 3 再将6从后面入队 但是,为了满足队列从左至右的单调性,我们将2,3出队 此时队列:6 再将1从后面入队 此时队列:1 6 再将1从后面入队 此时队列:1 1 6 再将2从后面入队 但是,为了满足队列…
题目链接:https://www.luogu.org/problemnew/show/P1993 1.差分约束: 对于a - b <= c 有一条 b-->a 权值为c 对于a - b >= c 有一条 a-->b 权值为-c 对于一个差分约束系统,若存在负环则无解 2.dfs版SPFA判负环 #include <queue> #include <cstdio> #include <cstring> #include <iostream&g…
题目链接:https://www.luogu.org/problemnew/show/P1726 菜 #include <stack> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 50000 + 10; int n, m, root; struct edge{…
题目链接:https://www.luogu.org/problemnew/show/P2146 变量名真毒瘤 我真的再也不把l,left,r,right弄反了 反向思维更好做一些 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define ll long long #define lson left, mid, rt<<1 #defi…
题目链接:https://www.luogu.org/problemnew/show/P1314 二分答案 但是计算区间贡献的时候 直接暴力会挂 前缀和加速 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define ll long long using namespace std; const int maxn = 2000000 + 10; l…
题目链接:https://www.luogu.org/problemnew/show/P3709 离散化+区间众数..? #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int maxn = 500000+10; inline int read() { int k=0; char c; c=getcha…