Codeforces
THE END GAME
这个作者很懒,什么都没留下…
展开
-
CF685B Kay and Snowflake
CF685B Kay and Snowflake题意:输入一棵树,判断每一棵子树的重心是哪一个节点.题解:首先关于重心:一棵树将某个点去掉,会把这棵树分为好几块,以最大的一块的结点个数作为maxsizemaxsizemaxsize,这样的话每一个点都对应着一个maxsizemaxsizemaxsize,这些值当中最小的那个所对应的结点即为树的重心。定义:Gson[i]Gson[i]Gson...原创 2019-10-29 18:00:14 · 152 阅读 · 0 评论 -
暑假集训日记——7.18(codeforce)
C. Basketball Exercise题解:我也是醉了,我说我咋连一道简单dp的题都写不对…题意理解错了…写成了:单调递减子序列的最大和:#include<bits/stdc++.h>#define mp make_pairusing namespace std;typedef long long ll;typedef pair<int, int> ...原创 2019-07-20 10:04:17 · 164 阅读 · 0 评论 -
暑假集训日记——7.15(ST表+单调栈/单调队列+codeforce)
C. From S To T模拟题#include<algorithm>#include<cstdio>#include<cmath>#include<iostream>#include<cstring>#include<functional>#include<set>#include<ma...原创 2019-07-16 09:57:31 · 411 阅读 · 0 评论 -
暑假集训日记——7.4(codeforces)
B. Email from Polycarp题解:水题,练习一下STL,方便很多#include<algorithm>#include<cstdio>#include<cmath>#include<iostream>#include<cstring>#include<set>#include<map&g...原创 2019-07-06 14:05:00 · 247 阅读 · 0 评论 -
暑假集训日记——7.1/7.2(codeforce+分块的题)
emmmmmm,受最近集训的影响,看啥都像二分+前缀和…然后超时了题面:字母商店橱窗是一个字符串ss,由nn小写拉丁字母组成。正如名字所示,信件在商店里出售。信件从最左边到最右边一个一个地卖出去。任何客户只能从字符串ss中购买一些字母前缀。有m的朋友,他们中的第2个叫ti。他们每个人都计划估算如下的价值:如果s/他想要构建他/她所购买的字母的名称,他/她需要购买多少个字母(最短前缀的长度)...原创 2019-07-06 14:05:52 · 213 阅读 · 0 评论 -
暑假集训日记——7.9/7.10(scc习题+codeforce)
F. Simple Cycles Edges题解:要求求简单环,所以可以用tarjan求出点双连通分量,然后判断这个点双连通分量中的点的个数是否等于边的条数(有且仅有边的条数等于点的个数,才是个简单环),如果是的话把连通分量中的所有边存到一个数组中,最后找出所有边之后对边的编号进行排序输出就好了。#include<bits/stdc++.h>using namespace st...原创 2019-07-10 15:48:57 · 365 阅读 · 0 评论 -
暑假集训日记——7.13(单调栈/单调队列+codeforce)
C. Tokitsukaze and Discard Items按照题意模拟即可…可惜B题就做懵了#include <bits/stdc++.h>using namespace std;typedef long long ll;const int MAX=1e5+10;ll p[MAX];int main(){ ll n,m,k; scanf("%lld%lld%l...原创 2019-07-13 16:42:30 · 947 阅读 · 0 评论 -
暑假集训日记——7.11(codeforce+二分图+网络流)
B. The Golden Age题解:没啥题解,暴力,暴力出奇迹#include<algorithm>#include<cstdio>#include<cmath>#include<iostream>#include<cstring>#include<functional>#include<set&g...原创 2019-07-13 12:02:34 · 117 阅读 · 0 评论 -
暑假集训日记——7.3(codeforces)
C. System Administrator鲍勃在X公司找到了一份系统管理员的工作。他的第一个任务是在m双向直接连接的帮助下连接n台服务器,以便能够通过这些连接将数据从一台服务器传输到任何其他服务器。每个直接连接必须连接两个不同的服务器,每对服务器最多应该有一个直接连接。Y公司X公司的商业对手,让鲍勃一个他无法拒绝的条件:鲍勃被要求连接服务器以这样一种方式,当服务器索引v失败,其他两个服务器...原创 2019-07-06 14:05:27 · 127 阅读 · 0 评论 -
C. Problem for Nazar
题解:At first let’s simplify the problem. Let’s denote as f(x) function that returns sum of the elements that are on positions from 1 to x inclusive.How to implement function f(x)?To find the answer...原创 2019-06-01 14:28:09 · 127 阅读 · 0 评论 -
B. Dima and a Bad XOR
题解:Let’s take the first number in each array.Then, if we have current XOR strictly greater than zero we can output an answer.And if there is some array, such that it contains at least two distinct...原创 2019-06-01 13:41:02 · 87 阅读 · 0 评论 -
暑假集训日记——7.20(GCD+codeforce)
A - Maximum GCD 0 与 7的 最大公约数是 7,范围错误的话会出错#include<bits/stdc++.h>#define mp make_pairusing namespace std;typedef long long ll;typedef pair<int, int> pii;typedef pair<ll, int> ...原创 2019-07-21 14:10:46 · 95 阅读 · 0 评论 -
暑假集训日记——7.21(区间dp+codeforce)
D. Prime Graph题解:#include <iostream>using namespace std;bool prime(int x) { if (x < 2) return false; for (int i = 2; i*i <= x; ++i) { if (x%i == 0) return false; ...原创 2019-07-22 15:14:44 · 174 阅读 · 0 评论 -
暑假集训日记——7.23(codeforce)
D. Beautiful Graph二分图+联通分支+快速幂…我是打算这么求得,但好像太麻烦了…#include <bits/stdc++.h>using namespace std;const int N = int(3e5) + 999;const int MOD = 998244353;int n, m;vector <int> g[N];in...原创 2019-07-27 13:41:14 · 112 阅读 · 0 评论 -
暑假集训日记——8.18(codeforce)
E - 染色 题意:给定一棵有 nnn个节点的无根树和 mmm个操作,操作有 222类:1、将节点 aaa到节点 bbb路径上所有点都染成颜色 ccc2、询问节点 aaa到节点 bbb路径上的颜色段数量(连续相同颜色被认为是同一段),如“112221”“112221”“112221”由3段组成:“11”、“222”和“1”“11”、“222”和“1”“11”、“222”和“1”。请你写一...原创 2019-08-20 08:42:27 · 141 阅读 · 0 评论 -
暑假集训日记——8.17(codeforce)
C. Watching Fireworks is Fun题意:一条街道有 nnn个区域。 从左到右编号为 111到 nnn。 相邻区域之间的距离为 111。在节日期间,有 mmm次烟花要燃放。 第 iii次烟花燃放区域为aia_iai,幸福属性为bib_ibi,时间为tit_iti。ti⩽ti+1t_i⩽t_i+1ti⩽ti+1如果你在第 iii次烟花发射时在x(1⩽x⩽n)x(1...原创 2019-08-18 09:11:20 · 93 阅读 · 0 评论 -
暑假集训日记——8.15(codeforce)
题意:从坐标(0,0)(0, 0)(0,0)到(n,0)(n, 0)(n,0)的折线,这条折线每向右延伸一个单位长度,高度要么不变,要么+1+1+1,要么−1-1−1,已知 nnn,求这种折线种数题解:卡特兰数+组合数如果只能上下就是卡特兰数,但还存在平移操作。原式: ans[k]=C2kk×Cn2kk+1ans[k]=\frac{C_{2k}^{k}\times C_{n}^{2k}}{...原创 2019-08-17 08:32:08 · 96 阅读 · 0 评论 -
暑假集训日记——8.14(codeforce)
E. 3-cycles题意:使得图中不存在长度为3的环,求满足条件的最多边的数目题解:二部图的任意两点的最小环长度大于3#include<bits/stdc++.h>#define mp make_pair#define se second#define fi firstusing namespace std;typedef long long ll;typed...原创 2019-08-15 14:27:34 · 160 阅读 · 0 评论 -
暑假集训日记——8.18(codeforce)
D. Shortest Cycle题意:一个环至少有333个点,aaa&b!b!b!=000 的两个点间有一条边,求最小环题解:floyedfloyedfloyed求解最小环O(n3)O(n^3)O(n3)emmm想到了范围问题,然后就使劲考虑怎么建环,emmm赛后发现有现成的模板…其实就是DP。#include<bits/stdc++.h>#define mp m...转载 2019-08-30 22:10:11 · 78 阅读 · 0 评论 -
暑假集训日记——8.9(codeforce)
C. Ayoub and Lost Array题意:给出一个数组的长度以及数组中元素的取值范围,问:有多少种方案使得数组的元素的总和为三的倍数。题解:动态规划dp[i][j]dp[i][j]dp[i][j]表示 由 iii个数的和余 jjj的组合有多少组dp[i][0]=dp[i−1][0]∗a+dp[i−1][1]∗c+dp[i−1][2]∗bdp[i][0]=dp[i-1][0]*a...原创 2019-08-11 20:21:08 · 140 阅读 · 0 评论 -
暑假集训日记——8.6(codeforce)
D. Suitable Replacement题意:把 S串中的?转化为小写字母,使得字符串 S拥有最多的 字符串T的不相交字串,(S中的字母可以互换顺序)题解:贪心#include<bits/stdc++.h>#define mp make_pairusing namespace std;typedef long long ll;typedef pair<int...原创 2019-08-07 12:15:56 · 134 阅读 · 0 评论 -
暑假集训日记——8.13(codeforce)
A. Integer Sequence Dividing题意:给定一个整数序列1 2…n。你必须把它分成两个集合A和B每个元素都属于一个集合,|sum(A)−sum(B)| is minimum possible.题解:这种一看题面不是很难, 再一看复杂度1e9的题, 一定是规律题…哎#include<bits/stdc++.h>#define mp make_pair#...原创 2019-08-14 12:41:05 · 148 阅读 · 0 评论 -
暑假集训日记——7.16(单调栈/单调队列+codeforce)
C - Trade 题解:dp+单调队列#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<vector>#include<cmath>#include<queue>#include<stac...原创 2019-07-27 13:45:26 · 156 阅读 · 0 评论 -
D. Good Triple
题解:找到满足题意的区间,使满足l,r范围内有解当同一范围内的区间存在覆盖的情况,取小的区间可以使解尽量多所以暴力枚举可解枚举左端点,依次累加右端点距n的距离即为所求解的情况#include<algorithm>#include<cstdio>#include<cmath>#include<iostream>#include<...原创 2019-05-28 19:30:08 · 185 阅读 · 0 评论 -
C. Increasing by Modulo
二分#include<algorithm>#include<cstdio>#include<cmath>#include<iostream>#include<cstring>#include<set>#include<map>#include<iterator>#include&l...转载 2019-05-27 22:49:21 · 304 阅读 · 0 评论 -
Codeforces Round #552 (Div. 3) E
codeblock 不支持c++11,auto一直编译不过后来改了半天编译器#include<algorithm>#include<cstdio>#include<cmath>#include<iostream>#include<cstring>#include<set>#include<map>...原创 2019-04-18 18:31:26 · 83 阅读 · 0 评论 -
Codeforces Round #552 (Div. 3) D
二分法#include<algorithm>#include<cstdio>#include<cmath>#include<iostream>#include<cstring>#include<set>#include<vector>#include<string>using nam...原创 2019-04-17 19:56:16 · 85 阅读 · 0 评论 -
Codeforces Round #552 (Div. 3) C
暴力求解#include<algorithm>#include<cstdio>#include<cmath>#include<iostream>#include<cstring>#include<set>#include<vector>#include<string>using na...原创 2019-04-17 18:40:34 · 170 阅读 · 0 评论 -
Trailing Loves (or L'oeufs?)
【题解】:题意是:给你一个n,b。然后问在b进制下,n!的末尾有多少个0.首先我们回顾一下,在10进制下面,n的阶乘末尾零的计算方法是:把10=2*5,然后2为因子的个数有:n/2+n/(2^2)+n/(2 ^3)……然后5为因子的个数有:n/5+n/(5^2)+n/(2 ^3)……其实这个题目就是照葫芦画瓢,把所有b的质因子分解出来,然后看看哪一个质因子最少即可。#include...转载 2019-02-24 10:25:07 · 143 阅读 · 0 评论 -
Educational Codeforces Round 62 (Rated for Div. 2) C
贪心思想#include<iostream>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<string>#include<cstdio>#include<set>#include...原创 2019-03-27 17:09:19 · 103 阅读 · 0 评论 -
Codeforces Round #548 (Div. 2) C
一开始用广搜做的,明知道连通块用dfs简单…,改了半天依旧挂在样例11…,深搜一发过,打死不用广搜了…标程#include <bits/stdc++.h>using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);#define endl "\n"#define i...原创 2019-03-22 14:03:40 · 78 阅读 · 0 评论 -
Codeforces Round #546 (Div. 2) D
题解用数组num[x]记录数x后面可以与其交换的数的数目,当这个数目刚好等于这个数和最后一个数的距离时,肯定有办法能把最后一个数换到x的位置,然后需要注意的是要一直更新最后一个数的位置,它的位置就是n-ans(即数列长度-已经移动的次数)。#include<bits/stdc++.h>using namespace std;const int maxn=3e5+5;vec...转载 2019-03-20 19:46:55 · 132 阅读 · 0 评论 -
Codeforces Round #546 (Div. 2) C
InputCopy3 31 2 34 5 67 8 91 4 72 5 63 8 9OutputCopyYES#include<bits/stdc++.h>using namespace std;vector<int> A[1010];vector<int> B[1010];int main(){ int N, M; sc...原创 2019-03-20 19:13:07 · 107 阅读 · 0 评论 -
Codeforces Round #547 (Div. 3) E
ExamplesInputCopy1000 6-100 -200 -300 125 77 -4OutputCopy9InputCopy1000000000000 5-1 0 0 0 0OutputCopy4999999999996InputCopy10 4-3 -6 5 4OutputCopy-1#include<bits/stdc++.h>...原创 2019-03-20 18:33:40 · 75 阅读 · 0 评论 -
区间dp
一.什么是区间dp?顾名思义:区间dp就是在区间上进行动态规划,求解一段区间上的最优解。主要是通过合并小区间的 最优解进而得出整个大区间上最优解的dp算法。二.核心思路既然让我求解在一个区间上的最优解,那么我把这个区间分割成一个个小区间,求解每个小区间的最优解,再合并小区间得到大区间即可。所以在代码实现上,我可以枚举区间长度len为每次分割成的小区间长度(由短到长不断合并),内层枚举该长度下可...转载 2019-03-09 08:53:47 · 158 阅读 · 0 评论 -
Codeforces Round #515 (Div. 3) B
https://vjudge.net/contest/261555#problem/B与这个题有点类似的地方 贪心#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>using namespace s...原创 2019-04-18 20:29:33 · 105 阅读 · 0 评论 -
Codeforces Round #553 (Div. 2) D
题解:就是从小到大对(ai-bi)进行排序#include <bits/stdc++.h>using namespace std;typedef long long ll;const int inf = 0x3f3f3f3f;const int mod = 1e9 + 7;const int N = 1e5 + 10;struct node{ int a,b...转载 2019-04-28 17:24:54 · 105 阅读 · 0 评论 -
Educational Codeforces Round 64 Editorial D
#include<bits/stdc++.h>using namespace std;const int N = 200043;int p[2][N];//用二维数组存0和1int siz[2][N];int get(int x, int c)//获得根节点的数字{ if(p[c][x] == x) return x; return p[c][x] =...原创 2019-05-04 16:37:44 · 95 阅读 · 0 评论 -
B. Pairs
1.如果可以找出第两对数,且四个数完全不同,那么如果可以满足题意的话,那么那两个数一定在这四个数之中,那么暴力扫一遍就可以了2.若找不出,那么一定可以满足题意#include<algorithm>#include<cstdio>#include<cmath>#include<iostream>#include<cstring>...转载 2019-05-27 08:51:45 · 881 阅读 · 0 评论 -
B1. Cat Party (Easy Edition)
我一开始以为是使数字呈相同间隔!!@!@%*&&%&%%&%%%#%我想了一下午,!!@!@%*&&%&%%&%%%#%总之很简单的一道题删除一个数字使前缀中不同数字的个数相等f[i] 统计数字 i 的个数cnt[i] 统计相同数字有 i 个的 数的个数#inclu...转载 2019-05-11 16:16:55 · 298 阅读 · 0 评论