题意: 给定一个长度为 nnn 的数组 aaa,求有多少划分方式使得每段区间中出现次数为 111 的数字个数不大于 kkk,答案模 998244353998244353998244353。(n,k,ai≤105)(n, k, a_i \leq 10^5)(n,k,ai≤105) 链接: https://codeforces.com/contest/1129/problem/D 解题思路: 很容易得
牛客小白月赛22 B.树上子链 题意: 给定一棵树 T ,树 T 上每个点都有一个权值。 定义一颗树的子链的大小为:这个子链上所有结点的权值和 。 请在树 T 中找出一条最大的子链并输出。 思路: 类似树形dp求树的直径。 d(i)表示以点i到以i为根的子树任意一点的最大距离 dfs过程中我
设dp_i为已经出现了i面,需要的期望次数,dp_n=0 那么dp_i= i/n*dp_i + (n-i)/n*dp_(i+1) + 1 现在已经i面了,i/n的概率再选择一次i面,(n-i)/n的概率选到新的一面,分别乘其期望次数,并且这次丢过,所以+1 #include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x)&(-x)) type
纯板子题,入队时保证单调性,即单调栈,出队保证题目条件,本题即窗口长度k,在入队出队时都可以维护信息 const int maxm = 1e6+5; int buf[maxm], maxq[maxm], minq[maxm], ans1[maxm], ans2[maxm]; int main() { ios::sync_with_stdio(false), cin.tie(0); int n, k, l1 = 0
typedef long long LL; typedef pair<LL, LL> PLL; const int maxm = 1e4+5; const int maxn = 1e7+5; int ans[maxn]; int head[maxm], cnt, siz[maxm], mxson[maxm], mxsum, rootsum, root, dis[maxm], point; bool vis[maxm]; struct Node { int v, next, va
Your task in this problem is to determine the number of divisors of Cnk. Just for fun -- or do you need any special reason for such a useful computation? Input The input consists of several instances. Each instance consists of a single line containing two
The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are smaller than n and coprime to n, and this function has a lot of beautiful characteristics. Here comes a very easy question: suppos
有n朵花,每朵花有三个属性:花形(s)、颜色(c)、气味(m),用三个整数表示。 现在要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量。 定义一朵花A比另一朵花B要美丽,当且仅Sa>=Sb,Ca>=Cb,Ma>=Mb。 显然,两朵花可能有同样的属性。需要统计出评出每个等级的花的数量。 I
题意 先不考虑没有\(d\)的限制,此时每场比赛只有两种选择,这是一个典型的\(2-SAT\)模型。 发现\(d\)很小,自然想到枚举每个\(x\)用哪种车,但是\(3^dm\)显然是过不了的。于是我们枚举这个\(x\)不能用那种车,此时我们只需要枚举两个即可,因为此时三种车\(ABC\)都被放到\(x\)上判断过了。 c
题意 获得一条边的价值必须选上两点,这一看就是最大权闭合子图。 先将所有价值选上。 从\(S\)向每个用户\(i\)连容量为\(C_i\)的边,从每个中转站\(i\)向汇点连容量为\(cost_i\)的边,对于每个用户\(i\)从\(i\)向\(A_i\)和\(C_i\)连容量为\(inf\)的边。 之后跑最小割,用答案减去即可。 c
ttps://loj.ac/problem/10064 题目描述 给出一张图,求它最短路径树的个数。 思路 最短路径树就是对于根节点\(u\),它到任意\(v\)的最小距离等于树上的距离。我们考虑\(dijkstra\)的过程,每一次选择一个与起始节点距离最小的点加入已确定的集合,所以我们每次选择的边组成的集合
手机号码 题目描述 人们选择手机号码时都希望号码好记、吉利。比如号码中含有几位相邻的相同数字、不含谐音不吉利的数字等。手机运营商在发行新号码时也会考虑这些因素,从号段中选取含有某些特征的号码单独出售。为了便于前期规划,运营商希望开发一个工具来自动统计号段中满
满分做法: 几组样例充分说明,最优的子序列单调区间最多不超过两个。所以可以用树状数组维护三个值,一个是单增的最大值,一个是单减的最大值,一个是有拐点的最大值。最后离散化倒叙处理即可 #include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<cstdio>usi
#include<cstring>#include<queue>#include<cstdio>#include<iostream>#include<cmath>#include<algorithm>#include<vector>using namespace std;const int maxm=100007;int n,k;int pre[maxm],last[maxm],other[maxm],l;bool vis
满分做法: 把人向床连边进行二分图匹配即可。 #include<cstring> #include<algorithm> #include<cmath> #include<iostream> #include<cstdio> #include<queue> using namespace std; typedef long long ll; const int maxm=5555; int t,n,ans; int school[ma
50分做法: 可以发现答案具有单调性,所以二分答案。判断是否可行就需要DP。dp[i]表示到第i个格能得的最大值,从能跳向它的格进行转移即可。 #include<cstring> #include<algorithm> #include<cmath> #include<iostream> #include<cstdio> using namespace std; typedef long long ll;
满分做法: 枚举每个边作为生成树的最小边,再进行最小生成树求出最大边,做差比较即可。 #include<cstring> #include<algorithm> #include<cmath> #include<iostream> #include<cstdio> using namespace std; typedef long long ll; const int maxm=20007; int n,m,ans; int maxx; int
https://loj.ac/problem/10133 题目描述 给出一张图,求它的严格次小生成树。 思路 同秘密的牛奶运输,不再赘述。 代码 #include <bits/stdc++.h>using namespace std;typedef long long ll;const int MAXN=1e5+10,MAXM=3e5+10;const ll INF=1000000000000000;struct Edge{
有一个长度为n的数组{a1,a2,…,an}。m次询问,每次询问一个区间内最小没有出现过的自然数。 对于100%的数据:1<=n,m<=200000,0<=ai<=10^9,1<=l<=r<=n 题解 用主席树维护每个前缀区间中每个数最后出现的位置,查询时如果有某个数出现位置<l那么他就可以选。 有一些区间问题就是这种思路
description analysis 拆位从高位到低位贪心 对于当前位,如果把所有当前位为\(1\)的边塞入,\(1\)和\(n\)连通,则该位必须为\(1\) 这个是因为高位的\(1\)比所有低位的\(1\)都要优,用并查集维护连通性 对固定下的位,继续向下贪心,找低位中满足所有条件的\(1\)位即可 code #pragma GCC
题意: T组案例 每组案例: n个灯泡,m次操作 每次操作把区间(L,R)内的灯泡翻转(开变关,关变开) 问m次操作之后有多少灯泡是亮着的 链接 数据范围: T<=1e3 n<=1e6 m<=1e3 时限1s,内存8000k 分析: 空间小时间少恶心人 差分每组O(n)都tle 但是因为m小,所以考虑从m入手 比赛的时候一手离
题目 题解: 对于同方向(横竖的),同行最近相邻的两个连边。每个关键点被左右最近横向点连边,被上下最近纵向点连边,自由门按题意连,没有宝藏的点不连边,求强连通分量缩点后跑拓扑排序即可。 我打的好长啊。 AC Code: #pragma GCC optimize(2) #include<bits/stdc++.h> #define maxn
问题描述 永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自己的独一无二的重要度,按照重要度可 以将这 n 座岛排名,名次用 1 到 n 来表示。某些岛之间由巨大的桥连接,通过桥可以从一个岛 到达另一个岛。如果从岛 a 出发经过若干座(含 0 座)桥可以到达岛 b,则称岛 a 和岛 b 是连 通的
Description You may have wondered why most extraterrestrial life forms resemble humans, differing by superficial traits such as height, colour, wrinkles, ears, eyebrows and the like. A few bear no human resemblance; these typically have geometric or amor
题目描述 给定n个整数(数字可能重复),求在这些数中选取任意个,使得他们的异或和最大。 输入格式 第一行一个数n,表示元素个数 接下来一行n个数 输出格式 仅一行,表示答案。 输入 #1 2 1 1 输出 #1 1 分析: 模板题 code: #include<iostream> #include<cstdio> #include<cstring> #i