随笔分类 - codeforces
摘要:给一幅图,边从0开始每天多一条边,问每天增加边之后能够有多少人去旅游。 能去旅游的定义是只有当联通的点的度数都大于才能去旅游,否则都不能去旅游。 考虑从后往前遍历删边,当有点的度数小于k时将这个点从图中删去并把它的边删去。 #include <bits/stdc++.h> using namespa
阅读全文
摘要:给一个树上的BFS序列问是否合法,BFS都以1为根节点。 第一种做法比较容易想到,每遇到一个节点查找它后面的size节点是否在子树里在就推入队列,有不在的就不合法。 #include <bits/stdc++.h> #define lson l,mid,rt<<1 #define rson mid+
阅读全文
摘要:给一颗有根树,每个节点有一个字母,给m次询问,每次询问在i节点的子树下离根节点距离为d的所有节点的字母是否可以组合为回文串。 特别的,如果i节点下没有深度为d的节点都输出Yes。 我们统计每个节点下的子树所有深度的字母。用一个数组表示每个深度的26种字母。每次询问遍历26种字母如果总字母是奇数个且有
阅读全文
摘要:给一颗n个节点的树,每个节点上有一个颜色值,1为根节点。有m次询问,每次询问以vj为顶点的子树下颜色数量超过kj个的颜色总共有多少种。 考虑树上启发式合并。 首先将询问保存。每次加入新的节点的时候会把这个节点的颜色值+1,考虑我们把这个节点的颜色值的数量在树状数组中减去1,然后这个颜色值数量+1,在
阅读全文
摘要:给定一棵n个节点的树,每个节点有个权值,1为根节点。把任意节点为根的子树中权值出现次数最多的权值称为占领这个节点的权值。 然而次数最多的权值可能有多个,要求每个节点的占领这个节点所有权值的和。 每个子树上的答案互不相关,考虑用树上启发式合并。 用一个数组记录当前子树的所有权值出现的次数,有新的次数出
阅读全文
摘要:#include <cstdio> #include <cstring> #include <vector> using namespace std; int main(){ int a[210000],flag[210000],lag[210000],n; vector<int> vec; mem
阅读全文
摘要:#include <cstdio> int main(){ long long a,b,f,k,i,tot,s[11000],cnt; scanf("%lld%lld%lld%lld",&a,&b,&f,&k); tot=0,s[tot]=0,cnt=0; while(cnt<k*a){ tot++
阅读全文
摘要:#include <cstdio> #include <map> using namespace std; int main(){ int n,tot,max=0; map<char,int> mp; char a[210]; scanf("%d",&n); scanf("%s",a); for(i
阅读全文
摘要:题意:给你n个数再给一个数字K,问你最少多少个操作能让K前的数字都存在,K不存在。 题解:先删除所有的K,再补完前面缺少的数字。 代码: #include <cstdio>int N, cnt[101], K, O;int main(){ scanf("%d%d", &N, &K); for (in
阅读全文
摘要:题意:给你一个树形的二分图,问最多可以添加多少条边让其始终为二分图。 题解:利用二分图的染色判断出两个集合中各有多少个数,总的边数应该为两个集合顶点数乘积,所以输出乘积减n-1就可以了。 PS:注意要用long long,因为这个比赛的时候WA了无数发。。。 代码: # include<iostre
阅读全文
摘要:题目:一个人要买房,一共有n间在一排的房,有k间已经售出。但这个人只想买旁边有人居住的房,问最多有多少选择,最少有多少选择。 题解:当k==0或k==n时,max==min==0。一般情况时三个为一组,k--,tot+=2,n-=3;当n<3时,tot+=(n-k)。 代码: #include<cs
阅读全文
摘要:C. Leha and Function time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output C. Leha and Functio
阅读全文
摘要:B. Godsend time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output B. Godsend time limit per tes
阅读全文
摘要:B. 3-palindrome time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output B. 3-palindrome time limi
阅读全文
摘要:A. Fake NP time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Tavak and Seyyed are good frie
阅读全文

浙公网安备 33010602011771号