题意: 给出一个有向图,再给出6条原来不存在的路径,让你在这6条路径上添加一个最小的数,使图不存在负环. 思路: 直接6遍 floyd 输出就行了. #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> PII; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 <<…
同:https://www.cnblogs.com/--HPY-7m/p/11444923.html #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cstdlib>//malloc exit strcat itoa system("cls") #include <iostream>//…
题意: 查找区间k的后继. 思路: 直接主席树. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cstdlib>//malloc exit strcat itoa system("cls") #include <iostream>//pair #include <fstream&…
https://nanti.jisuanke.com/t/4 #include <bits/stdc++.h> using namespace std; ,; typedef unsigned long long ull; char str[N]; ull hl[N],hr[N],p[N]; ]; ull get(ull h[],int l,int r) { ]*p[r-l+]; } ; long long getval(int l,int r) { ) ; ; ) l++; ;i<=;…
https://nanti.jisuanke.com/t/41387 解: 离散化+线段树. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cstdlib>//malloc exit strcat itoa system("cls") #include <iostream>//pair…
https://nanti.jisuanke.com/t/41383 解: 斐波那契博弈+中国剩余定理. #include <bits/stdc++.h> using namespace std; ],m[],ans; long long exgcd(long long a,long long b,long long &x,long long &y){ if (!b) {x=,y=;return a;} long long re=exgcd(b,a%b,x,y),tmp=x;…
B. super_log 题意:研究一下就是求幂塔函数 %m的值. 思路:扩展欧拉降幂. AC代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; ; int a, b, m; ll eular(ll n) { ll ans = n; ;i * i <= n;i++) { ) { ans -= ans / i; ) n /= i; } } ) ans -= ans / n; return ans; }…
传送门 A. The beautiful values of the palace 题意: 给出一个\(n*n\)的矩阵,并满足\(n\)为奇数,矩阵中的数从右上角开始往下,类似于蛇形填数那样来填充. 之后会给出\(m\)个有效数字的坐标,坐标左下角为\((1,1)\),右上角为\((n,n)\),其余数字都为\(0\). 之后会有多个询问,每个询问给出一个子矩阵,问子矩阵中元素和为多少. 思路: 矩阵每个位置的数值可以\(O(1)\)计算: 将每个询问拆分成四个询问,接下来处理的问题就是怎么维…
题意:给出一个DAG,一只机器人从1点出发,等概率地选择一条出边走或者停留在原点,机器人的第k次行动消耗能量是k(无论是走还是停留都算一次行动).问1到n的期望. 解法:因为行动消耗的能量跟行动次数有关(有点像求E(x^2)的味道),考虑做两次概率DP. dp1[x]表示点x到终点n的期望天数,那么dp1[x]=( dp1[x]+sigma(dp1[y]) ) / (du+1) + 1 .(du是x点度数,y是x儿子). dp2[x]表示点x到终点n的期望代价,那么dp2[x]=( dp2[x]…
题目链接:https://nanti.jisuanke.com/t/41305 题目说的很明白...只需要反向跑spfa然后输入-dis,然后添-dis的一条边就好了... #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <map> #include <cmath>…
>传送门< 前言 这题比赛的时候觉得能做,硬是怼了一个半小时,最后还是放弃了.开始想到用二维前缀和,结果$n\leq 10^{6}$时间和空间上都爆了,没有办法.赛后看题解用树状数组,一看不就是二维树状数组么,结果时间是够了,然而$sum[maxn][maxn]$空间上就爆了.于是开始研究别人的代码,终于看懂了,就觉得很神奇,这个思想很妙,后来再看别的博客,原来是二维偏序(就是利用树状数组/$CDQ$分治求$M$个点中每个点横纵坐标均小于这个点的权值和) 题意 有一个$n\ast n(n\le…
Here is a square matrix of n * nn∗n, each lattice has its value (nn must be odd), and the center value is n * nn∗n. Its spiral decline along the center of the square matrix (the way of spiral decline is shown in the following figure:) The grid in the…
In Complexity theory, some functions are nearly O(1)O(1), but it is greater then O(1)O(1). For example, the complexity of a typical disjoint set is O(nα(n))O(*n**α(n)). Here α(n)α(n) is Inverse Ackermann Function, which growth speed is very slow. So…
题意: 给你螺旋型的矩阵,告诉你那几个点有值,问你某一个矩阵区间的和是多少. 思路: 以后记住:二维前缀和sort+树状数组就行了!!!. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cstdlib>//malloc exit strcat itoa system("cls") #include…
这题概率dp + 拓扑排序可以写 改天补解释 #include <bits/stdc++.h> using namespace std; const int maxn=1e5+10; vector<int>vec[maxn]; int indeg[maxn],seq[maxn]; double d[maxn],f[maxn]; int N,M,T,tot=0; void topo() { queue<int>q; q.push(1); tot=0; seq[tot++]…
(施工中……已更新DF) 比赛传送门:https://www.jisuanke.com/contest/3004 D. Robots(期望dp) 题意 给一个DAG,保证入度为$0$的点只有$1$,出度为$0$的点只有$n$. 现在一个机器人从$1$出发,每天都会以相同的概率前往相邻节点之一或静止不动. 每天机器人消耗的耐久等于经过的天数. 求机器人到点$n$期望消耗的耐久. 划水划的很愉快,唯一一道做出来的题.但是和题解做法不同(感觉我的方法麻烦),因此砸了3h在这题上面(正在试图读懂题解in…
F    Greedy Sequence You're given a permutation aa of length nn (1 \le n \le 10^51≤n≤105). For each i \in [1,n]i∈[1,n], construct a sequence s_isi​ by the following rules: s_i[1]=isi​[1]=i; The length of s_isi​ is nn, and for each j \in [2, n]j∈[2,n]…
https://nanti.jisuanke.com/t/41300 题意:求\(\sum_{i=1}^n\phi(i)\phi(j)2^{\phi(i)\phi(j)}\) \(f_i=\sum_{k=1}^n[\phi(k)==i]\) \(\sum_{i=1}^n\phi(i)\phi(j)2^{\phi(i)\phi(j)}\) \(=\sum_{i=1}^n\sum_{j=1}^nf_if_jij2^{ij}\) \(=2\sum_{i=1}^n\sum_{j=1}^if_if_jij…
题意 $S_{b}(n)$表示数字$n$在$b$进制下各位的和,对于给定的数$N$和$b$,求出$\sum_{n=1}^{N}S_{b}(n)$ $[ link ]$ 分析 题解上写的是签到题,这是个悲伤的故事. 直接$b$进制分解求$S_{b}(n)$,先预处理出$a[i][j]$表示$i$进制下从$1$到$j$每个数各位数求和后的总和 对于每组数据$O(1)$输出即可 Code #include <cstdio> const int n = 1e6+5; int a[11][n]; int…
The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力) 传送门:https://nanti.jisuanke.com/t/41400 题意: 给你三个数组a,b,c,要你求有多少个三元组(i,j,k),使得 \[ \begin{array}{l}{\left|A_{i}-B_{j}\right| \leq C_{k}, \text { and }} \\ {\left|B_{j}-C_{k}\right| \leq…
B.super_log (欧拉降幂) •题意 定一个一个运算log*,迭代表达式为 给定一个a,b计算直到迭代结果>=b时,最小的x,输出对m取余后的值 •思路 $log*_{a}(1)=1+log*_{a}(0)=1-1=0$ $log*_{a}(a)=1+log*_{a}(log_{a}(a))=1+log*_{a}(1)=1$ $log*_{a}(a^{a})=1+log*_{a}(a)=2$       .... 以此类推得$log*_{a}(a^{a^{a^{a^{a^{...}}}}…
传送门 B. Dudu's maze 题意: 是什么鬼东西???我读题可以读半小时QAQ 给出一张无向图,一个人在里面收集糖果,每个点都有一个糖果,特殊点除外.当他第一次进入特殊点时,会随机往一条边走:之后再进入特殊点时,直接退出. 问最后期望获得的糖果数为多少. 思路: 注意到这个人肯定会贪心走的,即是每次到一个连通块,肯定要把里面的糖果都拿完,然后再选一个随机走. 不管往哪个方向,还是类似地贪心走,将那个连通块走完. 所以就两次\(dfs\)好了,第一次\(dfs\)首先求出第一个连通块,然…
题意:https://nanti.jisuanke.com/t/41420 给你n个石子的重量,要求满足(Sum<=2*sum<=Sum+min)的方案数,min是你手里的最小值. 思路: 从最大重量的石子开始背包,每次ans+=dp[j-v[i]]就行了. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cst…
B. Light bulbs 思路:差分 + 离散化, 好不容易懂了差分却没想到离散化,还是要罗老板出马..... AC代码: #include<bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int t; cin >> t; ;i <= t;i++) { int n, m; cin >> n >> m; map<int , in…
这题其实就是瞎搞,稍微想一想改一改就能过. 排序按值的大小排序,之后从后向前更新node节点的loc值,如果后一个节点的loc大于(不会等于)前一个节点的loc,就把前一个节点的loc值设置为后面的loc值. 这样的话, 后面的节点的值是大于前面节点的,如果该节点的loc也大于前面节点的,说明前面节点的loc就没有用了,用后面更大的数的更大的loc就可以了. 之后是一个二分,二分写的时候要把各种情况处理清楚,比如,m的值为0,搜索的时候可能会搜到它自己,所以如果搜索val+m,搜到的节点的loc…
复杂度分析,询问一千次,区间长1e6,O(1e9)超时. 那么我们知道对于差分来说,没必要一个一个求,只需要知道区间长就可以了,所以我们定义结构体差分节点,一个头结点,一个尾节点. 这样tail.loc-head.loc就是整个区间长,该区间的实际的大小就是 Add标记的大小,Add标记就是从头加到尾. 排序2*m个差分节点,对于loc相同的节点,说明是同一个位置的差分,add合并就可以了,不需要进行统计,直接跳过本次循环. #include <bits/stdc++.h> using nam…
前言 最近有很多算不上事的事,搞得有点心烦,补题难免就很水,没怎么搞,自我检讨一番~~ 说实话网络赛题目的质量还是挺高的,题目都设计的挺好的,很值得学习.这场比赛那会只有我们大二的在做,其他人去参加$CCF$认证去了,赛后这题搞出来了,跟$lsq$一顿解释,说这个其实也不难,她就说但是你看就这个地方卡了多少人,那会才两百多人过了.的确,有的题目还是很考思维的.(个人感觉很久没写博客,写这篇还是有点混乱的,有些博主把这题加上离散化的标签,想起来好像是有那么点道理) 题意 有 $n $个灯泡,初始全…
题意:https://nanti.jisuanke.com/t/41422 对每一位进行找循环节规律就行了. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cstdlib>//malloc exit strcat itoa system("cls") #include <iostream&g…
题目链接:https://nanti.jisuanke.com/t/41387 题目大意:对于给定序列,求出对于每个位置求出比该数大于m的最靠右的位置. 思路:首先对序列进行离散化,然后对于每个数的下标更新到线段树上,然后对于每个位置的数考虑,二分查找比该数大于m的第一个位置到最右端,查找下标的最大值即可. 代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; ; int n,m; ],ans[maxn];…
H. Texas hold'em Poker 思路:根据每个牌型分等级,然后排序按照等级优先,最大值次之,次大值,最后比较剩下值的和. #include<bits/stdc++.h> using namespace std; ; struct node{ string name; ; ; ; ; }; node a[maxn]; bool cmp(const node &a, const node &b) { if(a.id != b.id) return a.id >…