A 模拟

B 发现对于每个连通块,只有为完全图才成立,然后就dfs

C 构造  想了20分钟才会,一开始想偏了,以为要利用相邻NO YES的关系再枚举,其实不难。。

考虑对于顺序枚举每一个NO/YES,与前一个需要用的的字符串有k-1个交集,只多了一个string

于是只要保证k-1个string不同,只通过当前的string来影响答案,

若YES,开一个新的串; NO,则和第一个串一样,以此让这个相同串在下一次枚举中消失。。

//怎么想到?  其实NO可能有多个相同名字,关系就很乱了,我们希望只有1个名字重复,且只重复1次,然后再接着考虑

D 考虑如何求树上所有点对的距离和 : 只需求出每条边对答案的贡献累加即可。

原问题转化为求所有  =L/k + f(L,k)/k  f(L,k):L最少加几才能是k的倍数

第一部分可以直接O(n)求,f(L,k)可以通过L%k的值得出,问题转化为求所有L%k的值为0..k-1分别有几组。

待统计的二点形成链,链有2种,一种是有某个点为LCA,否则是另一种。

对于情况1,直接dp O(nk)

情况2,dp记录前缀和,将孩子信息合并,O(n*k^2)

这数数题还是挺好的

Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)的更多相关文章

  1. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!

    Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...

  2. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C. Bear and Different Names 贪心

    C. Bear and Different Names 题目连接: http://codeforces.com/contest/791/problem/C Description In the arm ...

  3. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B - Bear and Friendship Condition 水题

    B. Bear and Friendship Condition 题目连接: http://codeforces.com/contest/791/problem/B Description Bear ...

  4. 【树形dp】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) B. Bear and Tree Jumps

    我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是, ...

  5. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)A B C 水 并查集 思路

    A. Bear and Big Brother time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. 【构造】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) A. Bear and Different Names

    如果某个位置i是Y,直接直到i+m-1为止填上新的数字. 如果是N,直接把a[i+m-1]填和a[i]相同即可,这样不影响其他段的答案. 当然如果前面没有过Y的话,都填上0就行了. #include& ...

  7. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) E

    Description Bear Limak prepares problems for a programming competition. Of course, it would be unpro ...

  8. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) D

    Description A tree is an undirected connected graph without cycles. The distance between two vertice ...

  9. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C

    Description In the army, it isn't easy to form a group of soldiers that will be effective on the bat ...

随机推荐

  1. 类的扩展之 DataReader的扩展

    看了关于DataReader的扩展,发现能节省很多代码.从数据库读取数据最原始方法就是while()然后做循环,如果数据库添加一个字段那么你所有读取数据库的方法全部添加.通过扩展这个类就摆脱了这种令人 ...

  2. java list根据id获取子节点

    工作中因业务需求,将数据库中的树状结构的数据根据父节点获取所有的子节点 实现思路 1.获取整个数据的list集合数据 2.将数据分组,java8 list有groupby分组,java8之前的自己遍历 ...

  3. php常用的几个预定义变量

    __FILE__:返回所在路径文件名和文件名称 __DIR__:返回文件所在的完整目录 __LINE__:返回当前文件代码的行号 __CLASS__:返回当前类名 __FUNCTION__:返回当前方 ...

  4. Linux建立互信关系(ssh公钥登录)

    Linux有多种登录方式,比如telnet.ssh.支持ssh登录方式:口令登录和公钥登录 ssh登录方式:ssh [-l login_name] [-p port] [user@]hostname ...

  5. eos合约案例导读

    为了帮助大家熟悉 EOS 智能合约,EOS 官方提供了一个代币(资产)智能合约 Demo -- eosio.token.eosio.token 智能合约目前还不是特别完善,个别功能还没有完成.但这个示 ...

  6. 动态语言的灵活性是把双刃剑 -- 以 Python 语言为例

    本文有些零碎,总题来说,包括两个问题:(1)可变对象(最常见的是list dict)被意外修改的问题,(2)对参数(parameter)的检查问题.这两个问题,本质都是因为动态语言(动态类型语言)的特 ...

  7. Scrum立会报告+燃尽图(十月二十六日总第十七次)

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2246 项目地址:https://git.coding.net/zhang ...

  8. 自我介绍for软件工程课程

    石家庄铁道大学学生,正在学习软件工程课程. 对于软件工程课程,没什么太大的希望.度了一下,发现软件工程课程近年来比较脱节,这次用新课本不知道效果怎么样.嗯,等课本到手看看再说吧. 自己的目标:我希望能 ...

  9. HDU 5233 Gunner II 离散化

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5233 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  10. javascript方法扩展

    String.prototype.startWith = function(str){ return str.indexOf(str) == 0; }; var str = "abc&quo ...