http://codeforces.com/contest/322/problem/E E. Ciel the Commander time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name sai…
E. Ciel the Commander Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/322/problem/E Description Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has n cities connected by n - 1 undirected ro…
http://codeforces.com/contest/782/problem/E 题目大意: 有n个节点,m条边,k个人,k个人中每个人都可以从任意起点开始走(2*n)/k步,且这个步数是向上取整的.要求:着k个人要走完所有的节点,且每个人至少走1步. 思路:= =dfs找一棵树,一棵树是n-1条边,所以从树根开始走完所有的,也就只有n*2-2步,所以不会达到上限.md这么简单都没有想到,233 //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #incl…
题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string> #include <cmath> #include <…
Vasiliy's Multiset 题目链接: http://codeforces.com/contest/706/problem/D Description Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given q queries and a multiset A, initially containing only integer…
题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相邻的位置,更新长度为r - l - 1的最大值,感觉线段树结构体封装不错! 详细解释:http://blog.csdn.net/u010660276/article/details/46045777 其实还有其他解法,先掌握这种:) */ #include <cstdio> #include &l…
Codeforces Round #588 (Div. 2)-E. Kamil and Making a Stream-求树上同一直径上两两节点之间gcd的和 [Problem Description] 给你一棵树,树上每个节点都有一个权值.定义\(1\sim v\)的最短路径所经过的所有节点\(u\)称为\(v\)节点的祖先.定义函数\(f(u,v)=gcd(u,t1,t2,\dots,v)\),其中\(u,t1,t2,\dots\)都是\(v\)的祖先.求\(\sum f(u,v)\). […
题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLSL SLSLS LSLSL SLSLS SSSSS */ #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <string> usi…
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数)为k个.求序列. 思路:1~k+1.构造序列前段,之后直接输出剩下的数.前面的构造能够依据,两项差的绝对值为1~k构造. AC代码: #include <stdio.h> #include <string.h> int ans[200010]; bool vis[100010]; i…
Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/482/problem/A Description Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct posi…
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; int a[MAXN]; int main(void) //Codeforces Round #…
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少步,按照这个次数之后的能否满足要求 题目读的好累:( */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath>…
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况讨论一下 */ /************************************************ * Author :Running_Time * Created Time :2015-8-6 0:23:37 * File Name :B.cpp *****************…
题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /************************************************ Author :Running_Time Created Time :2015-8-3 10:49:53 File Name :C.cpp *************************************************/ #in…
题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ Author :Running_Time Created Time :2015-8-3 9:14:02 File Name :B.cpp *************************************************/ #include <cstdio> #include &…
题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************************ Author :Running_Time Created Time :2015-8-3 8:43:02 File Name :A.cpp *************************************************/ #include <cstdio>…
题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /************************************************ Author :Running_Time Created Time :2015-8-2 9:20:01 File Name :B.cpp **************************************…
题目传送门 /* 构造:从大到小构造,每一次都把最后不是9的变为9,p - p MOD 10^k - 1,直到小于最小值. 另外,最多len-1次循环 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long ll; ; const int INF = 0x3f3f3f3f; int…
题目传送门 /* 构造:结构体排个序,写的有些啰嗦,主要想用用流,少些了判断条件WA好几次:( */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <vector> #include <map> #include <iostream> #include <string> using name…
预备知识 树分治,树链剖分   poj1741 •一棵有n个节点的树,节点之间的边有长度.方方方想知道,有多少个点对距离不超过m 题解 点分治模板题.详见我早上写的http://www.cnblogs.com/chouti/p/5836926.html   OrzFang Ⅸ •有一棵n个点,边长为1的树,他要在树上选择一个大小为m的点集,使得这m个点两两距离相等. 方方方想知道这么做的方案数对998244353取模后的结果. 题解 首先肯定有一个中心点,使得这个点到m个点距离相等 那么枚举这个…
题目链接:G. New Roads 题意:给出n个结点,t层深度,每层有a[i]个结点,总共有k个叶子结点,构造一棵树. 分析: 考虑一颗树,如果满足每层深度上有a[i]结点,最多能有多少叶子结点 那么答案很简单,就是对(a[i]-1)求和再加1(每一层的结点都集中在上一层的一个结点上)   同理,我们考虑最少能有多少叶子结点,就是把上一个的答案再减去min(a[i]-1, a[i-1]-1)的求和,就是每一层的结点都尽可能的分散在上一层的结点 根据这个,那么如果要求有k个叶子节点,k在最大值与…
C. Link Cut Centroids Fishing Prince loves trees, and he especially loves trees with only one centroid. The tree is a connected graph without cycles. A vertex is a centroid of a tree only when you cut this vertex (remove it and remove all edges from…
题目链接: 题目 E. George and Cards time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 George is a cat, so he loves playing very much. Vitaly put n cards in a row in front of George. Each card has one integer written on it. All cards had…
E. Anton and Permutation time limit per test 4 seconds memory limit per test 512 megabytes input standard input output standard output Anton likes permutations, especially he likes to permute their elements. Note that a permutation of n elements is a…
C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain it…
E. Editor The development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text. Your editor consists of a line with infinite length and cursor, which points to the current character. Please note that…
链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text. Your editor consists of a line with infinite length and cursor, which point…
让你构造一棵树(给定了总结点数和总的叶子数),使得直径最小. 就先弄个菊花图(周围一圈叶子,中间一个点),然后平均地往那一圈放其他的点即可. #include<cstdio> using namespace std; int n,K,Ks[200010],x[200010],y[200010],ans,e; int main(){ scanf("%d%d",&n,&K); for(int i=1;i<=K;++i){ Ks[i]=1; } int no…
题目链接:http://codeforces.com/contest/1041/problem/E 题意:给出n - 1对pair,构造一颗树,使得断开其中一条边,树两边的最大值为 a 和 b . 题解:显示最大值出现的次数为n - 1,且i点出现的次数小于等于i.一个数字 i(< n)出现的次数为 i 到 n 的距离,可构造出一条链使得满足条件. #include <bits/stdc++.h> using namespace std; #define ll long long #de…
传送门 题意 n个点有n-1条边相连,其中有k个特殊点,要求: 删去尽可能多的边使得剩余的点距特殊点的距离不超过d 输出删去的边数和index 分析 比赛的时候想不清楚,看了别人的题解 一道将1个联通块转化为k个树的题目,考虑上界,应该是k-1条边,这k-1条边是原图中连接树与树的边,那么我们操作如下: 1.将特殊点i染色为i,放入队列 2.做一次bfs,对每个点相邻的点染色并判断 3.遍历边,如果边的两点不同色,则输出边的index trick 代码 #include <cstdio> #i…