51nod 1297】的更多相关文章

一个初始为空的二叉搜索树T,以及1到N的一个排列P: {a1, a2, ..., aN}.我们向这个二叉搜索树T添加这些数,从a1开始, 接下来是 a2, ..., 以aN结束.在每一个添加操作后,输出T上每对节点之间的距离之和. 例如:4 7 3 1 8 2 6 5.最终的二叉树为:          4      /   \     3      7      /      /   \  1      6     8   \    /    2  5   节点两两之间的距离和 = 6+5+5…
思路: 搞个栈模拟一下,也才5w; 直接wa1了..然后想到井口如果都进不去那就...一定GG了. 所以维护一下从井口到井底是非递增的就好了: #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <stack> #include <queue> using namespace std; stack<int>…
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1297 先是暴力加优化T了最后两个点…… 我还是来想想正解吧. 先写棵线段树把二叉搜索树建出来,然后在树上做下点分治就好了. #include<cstdio> #include<cstring> #include<algorithm> #define lp (p<<1) #define rp ((p<<1)|1…
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 用杜教筛求积性函数\(f(n)\)的前缀和\(S(n)=\sum\limits_{i=1}^nf(i)\),需要构造一个\(g(n)\)使得\(\sum\limits_{d|n}f(d)g(\frac nd)\)和\(\sum\limits_{i=1}^ng(i)\)都可以快速求出.因为我们有公式…
51Nod  1268  和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使他们的和为K.如果可以,输出:"Yes",否则输出"No". Input 第1行:2个数N, K, N为数组的长度, K为需要判断的和(2 <= N <= 20,1 <= K <= 10^9) 第2 - N + 1行:每行1个数,对应数组的元素A…
51Nod   1428  活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活动安排问题 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 有若干个活动,第i个开始时间和结束时间是[Si,fi),同一个教室安排的活动之间不能交叠,求要安排所有活动,最少需要几个教室?  Input 第一行一个正整数n (n <= 10000)代表活动的个数.…
51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 平面上有N个圆,他们的圆心都在X轴上,给出所有圆的圆心和半径,求有多少对圆是相离的. 例如:4个圆分别位于1, 2, 3, 4的位置,半径分别为1, 1, 2, 1,那么{1, 2}, {1, 3} {2, 3} {2…
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1501 dp求出环状不连续的前缀和,剩下东西都可以算出来,比较繁琐. 时间复杂度\(O(n+m)\). #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const int N = 500003; in…
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1622 简单题..直接暴力快速幂 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const ll p = 1000000007; int main() { ll A, B, C; scanf(&qu…
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1616 这道题主要是查询一个数是不是原有集合的一个子集的所有数的gcd. 只要枚举一个数的倍数暴力判断就可以了,时间复杂度\(O(alna),a=10^6\) #include<cstdio> #include<cstring> #include<algorithm> using namespace std; bool vis[1000003];…