目录 题意: 分析: @(2019牛客暑期多校训练营(第八场)E_Explorer) 题意: 链接 题目类似:CF366D,Gym101652T 本题给你\(n(100000)\)个点\(m(10000)\)条边,每无向边允许通过编号在\([Li,Ri](1\le Li\le Ri\le 1e9)\)内的人,问从\(1\)到\(n\)能通过多少个人. 分析: 赛中艹了30多发暴力无济于事... 因为以前做过一道数据范围1000的原题,当时做法好像是离散化后枚举区间暴力跑\(dfs\)查询或者带着…
题目地址 题意 给你一颗树 初始点颜色全部为白色 对于每一个满足要求一的点集s f(s)的定义为先把点集内的点染黑 满足要求二的路径集合数量 要求一为两两黑点之间不能出现白色的点 要求二为将这个路径集合上所有点染红(起始不能为黑色) 染红后使得每个初始染黑的点相邻的点为红或黑色 例如样例 2 1 2 2 3 选1这个点集的话 我们可以选择 {2-2},{2-3},{2-2,3-3},{2-3,2-2},{2-3,3-3},{2-3,2-2,3-3}这六种路径集 则f({1})=6 题目要求你求出…
目录 题意: 分析: @(2019牛客暑期多校训练营(第八场)D_Distance) 题意: 在三维空间\((n\times m\times h\le 100000)\)内,有\(q(q\le 100000)\)次操作.操作\(1\):添加一个点进入空间:操作\(2\):查询最近点对. 分析: 比赛时听G黄说完题意感觉看似好像裸题,一道在二维平面上操作完全的题:BZOJ2716 那么KD-Tree还是四维偏序问题呢?(原来都不是..出题人放出豪言:KD-Tree想过?不可能的 解法1:三维BIT…
小G砍树 dfs两次, dp出每个点作为最后一个点的方案数. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ(x) ((int)x…
传送门:https://www.nowcoder.com/acm/contest/203/B 思路及参考:https://blog.csdn.net/u013534123/article/details/82934820 这篇blog写得非常详细,但是我不会他说的立flag法,就学了其他同学的做法,如果不能做除法,就直接计数.我想了比较久明白的写在注释里啦. //#pragma GCC optimize(3) //#pragma comment(linker, "/STACK:102400000…
链接:https://www.nowcoder.com/acm/contest/140/J 来源:牛客网 White Rabbit has a rectangular farmland of n*m. In each of the grid there is a kind of plant. The plant in the j-th column of the i-th row belongs the a[i][j]-th type. White Cloud wants to help Whi…
链接:https://www.nowcoder.com/acm/contest/139/E 来源:牛客网 Bobo has a sequence of integers s1, s2, ..., sn ≤ si ≤ k. Find +) after removing exactly m elements. 输入描述: The input consists of several test cases and is terminated by end-of-file. The first line…
链接:https://www.nowcoder.com/acm/contest/139/A来源:牛客网 Count the number of n x m matrices A satisfying the following condition modulo (109+7). * Ai, j ∈ {0, 1, 2} for all 1 ≤ i ≤ n, 1 ≤ j ≤ m. * Ai, j ≤ Ai + 1, j for all 1 ≤ i < n, 1 ≤ j ≤ m. * Ai, j ≤…
链接:https://www.nowcoder.com/acm/contest/141/E来源:牛客网 Eddy likes to play with string which is a sequence of characters. One day, Eddy has played with a string S for a long time and wonders how could make it more enjoyable. Eddy comes up with following…
链接:https://www.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy has solved lots of problem involving calculating the number of coprime pairs within some range. This problem can be solved with inclusion-exclusion method. Eddy has implemented it lots of times…
链接:https://www.nowcoder.com/acm/contest/145/J来源:牛客网 You have a n * m grid of characters, where each character is an English letter (lowercase or uppercase, which means there are a total of 52 different possible letters). A nonempty subrectangle of th…
链接:https://www.nowcoder.com/acm/contest/143/J来源:牛客网 There are n students going to travel. And hotel has two types room:double room and triple room. The price of a double room is p2 and the price of a triple room is p3 Now you need to calulate the min…
链接:https://www.nowcoder.com/acm/contest/143/G来源:牛客网 Give two positive integer c, n. You need to find a pair of integer (a,b) satisfy 1<=a,b<=n and the greatest common division of a and b is c.And you need to maximize the product of a and b 输入描述: The…
链接:https://www.nowcoder.com/acm/contest/143/A来源:牛客网 Kanade selected n courses in the university. The academic credit of the i-th course is s[i] and the score of the i-th course is c[i]. At the university where she attended, the final score of her is …
G.coloring tree BFS计数 题目:给你n(<=5000)个节点的一颗树 你有K(<=5000)种颜色 你可以给每一个节点染一种颜色 总共有Kn种染色方法 在一种染色方法中 定义colorness为每一对相同颜色节点距离中的最短距离 问colorness为D时 有多少种染色方案 结果%mod 解:我们先求出>=D的方案数再减去>=D+1的方案数就是==D的方案数 现在问题变为>=X的方案数 可以看成对于任意一个节点,所有和它距离小于d的节点,不能和它有相同的颜色…
链接:https://ac.nowcoder.com/acm/contest/3800/D来源:牛客网 题目描述 Rinne 喜欢使用一种奇怪的方法背单词,现在这些单词被放在了一个 n×mn \times mn×m 的格子里.由于背单词是一个令人烦躁的事情,所以她决定每天只背同一行或者同一列的单词.她一共会背 T 次单词,为了方便巩固,她现在想知道:对于每个单词,最后一次背是什么时候呢? 她这么可爱当然会算啦!但是她想考考你. 输入描述: 第一行三个整数 n,m,T.接下来 T 行,第 i+1…
牛客小白月赛8 - E - 诡异数字 题意: 求区间中,满足限制条件的数字的个数. 限制条件就是某些数字不能连续出现几次. 思路: 比较裸的数位DP, DP数组开一个dp[len][x][cnt] 表示长度为len,x这个数字连续出现cnt次的个数. #include <iostream> #include <algorithm> #include <cstring> #include <string> #include <cstdio> typ…
D. Two Paths 题目连接: http://codeforces.com/contest/14/problem/D Description As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city t…
题意:又是最大01矩阵的模型了 这次要找的是极大0/1矩阵的个数 思路:我们像处理最大01矩阵那样处理一下边界 由于我们上左右已经无法再继续扩展 我们只需要用前缀和记录一下是否可以向下扩展(即判断当前的左右边界的下面是否都有1), 还要用一个标记数组记录一下同一矩阵 #include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int N = 3e3+7; const int inf = 0x…
题目传送门:https://www.nowcoder.com/acm/contest/144/J 题意:给一个function,构造n个数,求出其中任意两个的lcm的最大值. 分析:要求最大的lcm,大概分析一下,差不多就在里面的最大的k个里,k^2求出答案. 因为n(1e7),sort会tle,需要一个效率更低的排序来求出前k大. #include<bits/stdc++.h> using namespace std; ; typedef unsigned ui; typedef unsig…
题目: 题意:将1~n的数进行m次操作,每次操作将第pi位到pi+si-1位的数字移到第一位,求最后的排列. 思路:现在还没不会写splay,在知道这是splay模板题后找了一波别人的模板,虽然过了,但是感觉自己没学到什么,过几天去学一波splay,再回来把这题重写一次~ 代码实现如下: #include <map> #include <set> #include <cmath> #include <ctime> #include <stack>…
题目链接(貌似未报名的不能进去):https://www.nowcoder.com/acm/contest/141/A 题目: 题意:背包题意,并打印路径. 思路:正常背包思路,不过五维的dp很容易爆内存,比赛时无限爆,后面队友提醒用short就过了.不过也可以用滚动减少内存消耗,两种代码实现都贴一下吧~ 五维代码实现如下: #include <set> #include <map> #include <queue> #include <stack> #in…
起初看到这道题的时候,草草就放过去了,开了另一道题,结果开题不顺利,总是感觉差一点就可以做出来,以至于一直到最后都没能看这道题qaq 题意:类似于操作系统上讲的LRU算法,有两个操作,0操作代表访问其中的块,如果命中,将该块去除放到数组的末尾,未命中则在数组末尾加入当前块,1操作是询问数组中是否存在一个块,存在输出该块的数据,否则输出无效. 分析:考虑到只是对于数组的最后一个元素进行操作,所以可以使用链表进行模拟相关操作,主要的坑点就是时间卡的很紧所以需要加入快读,使用简单的hash将字符串映射…
由于其中的2操作非常多,我们就需要将其快速的更改,就会用到组合数的东西 其实自己手写一下就可以发现对于一个点增加的值在经过不断地前缀和累加过程中对于一点的贡献满足杨辉三角 所以我们就需要记录一下其中的2操作数,在线操作 一点(i,j)在进行t次操作后对于(t,y)的贡献为C(t-i+y-j-1,t-i-1); 对于查询时我们就需要将当前的t+1进行查询,就可以就可以快速知道该点对于区间内的所有值的贡献 #include<bits/stdc++.h> using namespace std; ;…
题意:1-n-1个数和1-n-1个数两两匹配,每次匹配将两个数的值进行与运算,要求每次匹配与运算的和相加最小,问满足匹配的配对方式 分析:打表前10个数与运算最小的匹配,我们发现,从n-1开始按位取反可以得到前面的一个值,这两个值的与运算结果为0 不管奇数还是偶数,前面和后面的数都可以两两匹配,偶数刚好匹配,奇数还剩下一个0,0可以与0匹配结果还是0 AC代码: #include <map> #include <set> #include <stack> #includ…
第一维直接遍历 第二维用线段树维护每个最左端可以得到的贡献 在线段树上每次删除一个点会影响到 X   X-R   X-2*R  3个值 最多操作1e5次 复杂度 6*n*logn(删了还要加回来 #include<bits/stdc++.h> using namespace std; ; int num[MAXN]; int number[MAXN]; struct Seg_Tre { int l, r; int w; } tree[MAXN << ]; inline void p…
题意: 给你边权,起点和终点,有k次机会把某条路变为0,问你最短路是多长. 思路: 分层最短路模板题.题目有点坑(卡掉了SPFA,只能用dijkstra跑的算法). #include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; ,INF=~; int N,M,K; int S,T; *MAXM*(MAXK+)+MAXK+];)+]; voi…
题意: 给你一串数,问你如题. 思路: 我不是这样的作法,从后往前,先取00,再算%3==0的个数,往前推的时候有递推关系: #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 <io…
题意: 给你一个数,希望你能用最少的3的倍数或运算成它,让你输出答案. 思路: 进制%3有规律,1.2.4.8.16%3是1.2.1.2.1 ... 利用这一点分情况取一些位合成一些数就是答案了. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cstdlib>//malloc exit strcat itoa sys…
思路: O(n)建一颗笛卡尔树,再O(n)dfs向上合并答案就行了. #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 &l…