AC日记——Broken BST codeforces 797d】的更多相关文章

D - Broken BST 思路: 二叉搜索树: 它时间很优是因为每次都能把区间缩减为原来的一半: 所以,我们每次都缩减权值区间. 然后判断dis[now]是否在区间中: 代码: #include <map> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 100005…
Broken BST CodeForces - 797D 题意:给定一棵任意的树,对树上所有结点的权值运行给定的算法(二叉查找树的查找算法)(treenode指根结点),问对于多少个权值这个算法会返回false. 方法:如果要求对于值x运行算法能访问到结点k,根据给定算法还有树,可以推出对于每个结点k的x的范围(即最小值,最大值)(某结点p左子树的结点的x全部小于p的权值,右子树的结点的x全部大于p的权值)(由于全部权值均为整数,即使只知道小于和大于也可以推出最小值.最大值). 然而,对于某个结…
Cards Sorting 思路: 线段树: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 100005 #define INF 0x3f3f3f3f #define maxtree maxn<<2 int n,ai[maxn],val[maxtree],L[ma…
F - Card Game 思路: 题意: 有n张卡片,每张卡片三个值,pi,ci,li: 要求选出几张卡片使得pi之和大于等于给定值: 同时,任意两两ci之和不得为素数: 求选出的li的最小值,如果不能到达给定值则输出-1: 二分+网络流最小割: 代码: #include <bits/stdc++.h> namespace data { #define maxn 105 #define maxque 200005 int val[maxn],mag[maxn],lev[maxn],num,l…
Success Rate 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define ll long long inline void in(ll &now) { ; ') Cget=getchar(); ') { now=now*+Cget-'; Cget=getchar(…
T-Shirt Hunt 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; ],ans; bool check(int xx) { if(xx<y) return false; )%; ;j<=;j++) { i=(i*+)%; +i) return true; } retur…
803D - Magazine Ad 思路: 二分答案+贪心: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 1000006 int k,ai[maxn],cnt,num,len,maxlen; char ch[maxn]; bool check(int lit) { ,ti…
797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 100005 ],size; inline void in(int &am…
803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于10^5时直接-1就好: 我们可以构造出gcd为1的序列为 1,2,3,4……n-k+1: 然后一个个枚举n的因子p: 1*p,2*p,3*p……(n-k+1)*p: 当枚举的p使得序列不满足于严格递增时,结束,输出合法答案: 来,上代码: #include <cmath> #include &l…
801A - Vicious Keyboard 思路: 水题: 来,上代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int len,ans; ]; int check() { ; ;i<len;i++) { ]=='K') res++; } return res; } int main() {…