题目链接: I - A Boring Problem UVALive - 7676 题目大意:就是求给定的式子. 学习的网址:https://blog.csdn.net/weixin_37517391/article/details/83821752 思路:证明过程在上面的博客中说了,大体意思就是预处理出两个前缀和,然后通过二项式定理化简式子就好了. AC代码: #include<bits/stdc++.h> using namespace std; # define ll long long…
16年北京现场赛的题,全场过的队30+. 初看只知道 O(N^2logK)的暴力,以为是什么变换. 仔细发现活用 二项式定理 就行. #include <bits/stdc++.h> using namespace std; #define fst first #define scd second #define pb(x) push_back((x)) #define mkp(x,y) make_pair((x),(y)) #define ist(x) insert((x)) typedef…
hihoCoder #1430 : A Boring Problem(一琐繁题) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 As a student of the school of electronics engineering and computer science in Peking University, Kyle took the course named Advanced Algebra in his freshma…
转载自https://blog.csdn.net/weixin_37517391/article/details/83821752 题解 其实这题不难,只要想到了前缀和差分就基本OK了. 我们要求的是第$i$项的式子: $F(i)=(a_1+a_2+...+a_i)^k+(a_2+...+a_i)^k+...+a_i^k$ 记$S_i = a_1 + a_2 +...+a_i,S_0=0$ $F(i) = (S_i-S_0)^k+(S_i-S_1)^k+...+(S_i-S_{i-1})^k$…
https://hihocoder.com/problemset/problem/1430 思路: 要用前缀去推Sigma总公式,比较方便.https://blog.csdn.net/weixin_37517391/article/details/83821752 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cstdli…
题意 : 度熊手上有一本神奇的字典,你可以在它里面做如下三个操作: 1.insert : 往神奇字典中插入一个单词 2.delete: 在神奇字典中删除所有前缀等于给定字符串的单词 3.search: 查询是否在神奇字典中有一个字符串的前缀等于给定的字符串 分析 : 利用字典树,插入操作时对于每一个节点的标记权值+1,代表此前缀+1,然后删除操作的时候尤为要注意的就是对于给出的前缀,不能在字典树上将权值置为0,因为如果现在假设已经插入了 abc.ab 现在要求 delete abc 则不能将 a…
题目大意 给你一棵\(n\)个点的树,每个点有一个颜色\(c_i\),每次给你\(x,y,k\),求从\(x\)到\(y\)的路径上出现次数第\(k\)多的颜色的出现次数 \(n,q\leq 100000\) 题解 树上莫队 先求出这棵树的dfs序(括号序列),记录每个点第一次出现的位置\(st_x\)和最后一次出现的位置\(ed_x\) 若每次询问的\(x,y\)中有一个是另一个的祖先(设\(x\)是\(y\)的祖先),那么就可以视为询问区间\([st_x,st_y]\) 可是一些不在这条链上…
题意:给定n, k,求出∑ni=1(k mod i) 思路:由于n和k都很大,直接暴力是行不通的,然后在纸上画了一些情况,就发现其实对于k/i相同的那些项是形成等差数列的,于是就可以把整个序列进行拆分成[k,k/2],[k/2, k/3], [k/3,k/4]...k[k/a, k/b]这样的等差数列,利用大步小步算法思想,这里a枚举到sqrt(k)就可以了,这样就还剩下[1,k/a]的序列需要去枚举,总时间复杂度为O(sqrt(k)),然后注意对于n大于k的情况,n超过k的部分全是等于k,为(…
Problem   UVALive - 3713 - Astronauts Time Limit: 3000 mSec Problem Description Input The input contains several blocks of test cases. Each case begins with a line containing two integers 1 ≤ n ≤ 100000 and 1 ≤ m ≤ 100000. The number n is the number…
Problem   UVALive - 3211 - Now or later Time Limit: 9000 mSec Problem Description Input Output Sample Input 10 44 156 153 182 48 109 160 201 55 186 54 207 55 165 17 58 132 160 87 197 Sample Output 10 题解:2-SAT问题板子题,这个问题主要是理论难度比较大,有了结论之后代码很容易,有专门的论文阐释算…
Problem   UVALive - 4287 - Proving Equivalences Time Limit: 3000 mSec Problem Description Input Output Sample Input 2 4 0 3 2 1 2 1 3 Sample Output 4 2 题解:题意就是给出一个有向图,问最少添加几条有向边能够使得整张图强连通,Tarjan缩点是比较容易想到的,之后怎么办,要用到一个结论:如果图中有a个入度为零的点,b个出度为零的点,那么max(a,…
Problem   UVALive - 5135 - Mining Your Own Business Time Limit: 5000 mSec Problem Description John Digger is the owner of a large illudium phosdex mine. The mine is made up of a series of tunnels that meet at various large junctions. Unlike some owne…
Problem  UVALive - 3523 - Knights of the Round Table Time Limit: 4500 mSec Problem Description Input The input contains several blocks of test cases. Each case begins with a line containing two integers 1 ≤ n ≤ 1000 and 1 ≤ m ≤ 1000000. The number n…
https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多为多少? 题解 一开始用贪心搞,搞到一半发现需要枚举的情况太多 只能用暴力搞,即枚举被去掉的两个区间,那么如何判断去掉哪两个区间比较好? 维护去掉后剩下的点数即答案 代码 #include<bits/stdc++.h> using namespace std; int n,q,i,j,l[5005…
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1044 前缀和优化. 但开成long long会T.(仔细一看不用开long long) #include<iostream> #include<cstdio> #include<cstring> #define ll long long using namespace std; ,M=; ; int n,m,a[N],pos[N]; ll dp[N],l,r,lm…
KMP算法: 一:next数组:next[i]就是前面长度为i的字符串前缀和后缀相等的最大长度,也即索引为i的字符失配时的前缀函数. 二:KMP模板 /* pku3461(Oulipo), hdu1711(Number Sequence) 这个模板 字符串是从0开始的 Next数组是从1开始的 */ #include <iostream> #include <cstring> using namespace std; ; int _next[maxn]; char S[maxn],…
http://www.lydsy.com/JudgeOnline/problem.php?id=1177 前缀和优化,时间复杂度$O(nm)$ 因为数据不全,快速读入会导致RE,切记! #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N = 1503; int in() { int k = 0, fh = 1; char c = getchar()…
  题目链接:http://acm.swust.edu.cn/problem/1026/     Time limit(ms): 3000 Memory limit(kb): 65535   hzf is crazy about reading math recently,and he is thinking about a boring problem. Now there are n integers Arranged in a line.For each integer,he wants…
A. Palindromes 留坑. B. Modules 将$a$排序,那么最优解中$a_n$一定放在前后一个,且前面$n-1$个每次要么放最小的,要么放最大的,区间DP即可. #include<cstdio> #include<algorithm> #include<bitset> #include<cmath> using namespace std; const int N=505,M=1000; int n,i,j,k,a[N],ans; bits…
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //2019.3.18 POJ 2251 Dungeon Master POJ 3278 Catch That Cow  //4.8 POJ 3279 Fliptile POJ 1426 Find The Multiple  //4.8 POJ 3126 Prime Path POJ 3087 Shuffle…
MASTERING CREATIVITY, 1st EditionThis guide is free and you are welcome to share it withothers.From James Clear:For most of my life, I didn't consider myself to be particularly creative. I didn't play a musicalinstrument (or even know how to read mus…
http://codeforces.com/problemset/problem/432/D 在前缀是后缀的前提下,求这个前缀在原串中出现了多少次 出现的次数可以用dp求解,前缀是后缀直接用Next判断,较为综合的kmp考察,这题没写出来就是kmp基础不牢,不应该 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std…
A. Harmonic Matrix Counter (3/19) B. Binary Tree (1/14) C. Asa's Chess Problem (21/65) [ Problem ] 给出一个棋盘格,里面的格子两两分为一组,组内的格子可以交换位置, 同一组格子一定在同一行或者同一列,每个格子为白色或者黑色, 现在要求每行中黑色的格子数量在rL到rR之间,每列中黑色的格子数量在cL到cR之间, 现在要求求出最少的交换次数使得要求被满足,不能满足则输出-1 [ Solution ] 我…
https://vjudge.net/problem/UVA-1210 统计质数前缀和,枚举左右端点,这一段的区间和+1 #include<cstdio> #define N 10001 using namespace std; int cnt,p[N],sum[N],ans[N]; bool v[N]; int main() { ;i<N;i++) { if(!v[i]) { v[i]=true; p[++cnt]=i; } ;j<=cnt;j++) { if(i*p[j]>…
POJ 3518 Boring Problem : 给一个串S,询问串S有多个子串出现至少两次且位置不重叠. Solution : 对S串建立后缀自动机,再建立后缀树,dfs一遍统计处每个结点的子树中最长节点max和最短节点min.枚举一遍后缀自动机的节点,那么对于其对应后缀的长度要求为小于等于max - min. #include <iostream> #include <algorithm> using namespace std; const int N = 1000008;…
[kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find The MultiplePOJ 3126 Prime PathPOJ 3087 Shuffle'm UpPOJ 3414 PotsFZU 2150 Fire GameUVA 11624 Fire!POJ 3984 迷宫问题HDU 1241 Oil Deposit…
题目涉及算法: 计数问题:枚举: 表达式求值:栈: 小朋友的数字:动态规划: 车站分级:最长路. 计数问题 题目链接:https://www.luogu.org/problem/P1980 因为数据量不大,所以直接枚举一下每个数,然后统计一下x出现的次数就可以了. 实现代码如下: #include <bits/stdc++.h> using namespace std; int n, x, cnt; int main() { cin >> n >> x; for (in…
专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find The MultiplePOJ 3126 Prime PathPOJ 3087 Shuffle'm UpPOJ 3414 PotsFZU 2150 Fire GameUVA 11624 Fire!POJ 3984 迷宫问题HDU 1241 Oil DepositsHDU 1495 非常可乐HDU 26…
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6336 Problem E. Matrix from Arrays Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1711    Accepted Submission(s): 794 Problem Description Kazari…
题目链接: A Boring Question Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description There are an equation.∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=?We define that (kj+1kj)=kj+1!kj!(kj+1−kj)! . And (kj+1kj)=…