题目:http://codeforces.com/problemset/problem/161/D 题意:给你一棵树,问你两点之间的距离正好等于k的有多少个 思路:这个题目的内存限制首先大一倍,他有5*1e5个点,k的范围是<=500,首先暴力n^2肯定不行,这个题其实很容易看出是树形dp 首先k的范围只有500,我们可以开一个dp[1e5][500]的dp数组,代表以这个点为上端点的所有情况,然后最后递归到1点处,dp[1][k]就是答案 #include<cstdio> #inclu…
统计树中长度为K的路径条数. 用f[u][k]表示从u结点的子树中出发,终止于u结点的长度为k的路径条数. 边dp边统计答案.为了防止重复统计,在枚举子节点的时候,先将该子节点和当前u结点(和前面已经统计过的子节点)的dp值统计到ans以后, 再把该子节点的dp值加到u结点的dp值中去. 这样,我们统计经过某个结点的长度为K的路径条数的时候,可以保证路径的两个端点来自其两个不同的子树或其本身,这样也是为了防止重复统计. #include<cstdio> using namespace std;…
VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) 代码 VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) A. Problem About Equation 每个杯子体积\[V=\frac{b+\sum{a_i}}{n}\] 判断是否有\(a_i > V\). B. File List 处理出'.'的位置. 第一个'.'和最后一个'.'特判字符长度是否合法. 连续的两点位置差\(d\in[2, 11]\)…
题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 /* 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 DP:很巧妙的从i出发向两头扩展判断是否相同来找回文串 dpr[i] 代表记录从0到i间的回文子串的个数,dpl[i] 代表记录i之后的回文子串个数 两两相乘就行了 详细解释:http://blog.csdn.net/shiyuankongbu/article/details/10004443 */…
我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是,我们现在只需要统计sigma((L+f(L,K))),最后除以K即可. 统计sigma(L)时,我们考虑计算每条边出现在了几条路径中,设u为edgei的子节点,那么这条边对答案的贡献就是siz(u)*(n-siz(u)),siz(u)为u的子树大小. 统计sigma(f(L,K))时,我们需要dp出…
题目链接:http://codeforces.com/problemset/problem/164/A 思路:用vector分别保留原图和发图,然后分别从val值为1的点正向遍历,va值为2的点反向遍历,如果某个点这两种方式都可以遍历到,则输出1,否则输出0. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector>…
D. Distance in Tree time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a tree is the length (…
VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/529/problem/E Description ATMs of a well-known bank of a sm…
Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and Big Brother 题意:我也没看太清,就是给你两个10以内的数a,b.a每天乘以3,b每天乘以2,求多少天后a大于b. 思路:应该是有公式的,不过看到数据这么小直接暴力乘求解.官方题解貌似就是这样,数据小就是水题. const int N=1e3+10; int main() { int a…
和FallDream组队瞎打一通--B两个人写的都挂了233,最后只剩下FallDream写的A和我写的C,最后我yy了个E靠谱做法结果打挂了,结束之后改了改就A了,难受. AC:AC Rank:180 Rating:2133-8->2125 A.Bear and Friendship Condition 题目大意:问一个无向图是否满足若a到b有边且b到c有边则a到c有边.(n<=150,000) 思路:判定每个连通块是不是团,不是则不满足,复杂度O(n). #include<cstdi…
题目链接: http://codeforces.com/problemset/problem/533/B B. Work Group time limit per test2 secondsmemory limit per test256 megabytes 问题描述 One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of…
题目链接:http://codeforces.com/contest/158/problem/E E. Phone Talks time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Cool J has recently become a businessman Mr. Jackson, and he has to make a l…
C. Cd and pwd commands Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/158/C Description Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he dec…
C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/problem/91/B Description One popular website developed an unusual username editing procedure. One can change the username only by deleting some characte…
Cd and pwd commands time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he…
A. Is it rated? time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to a…
A. Vicious Keyboard 题意:给你一个字符串,里面只会包含VK,这两种字符,然后你可以改变一个字符,你要求VK这个字串出现的次数最多. 题解:数据范围很小,暴力枚举改变哪个字符,然后check就好. #include<bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; int ans = 0; for(int i=0;i<s.size();i++){ if(s[i]=='V'){…
A. Is it rated? time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to a…
Description Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to re…
771C Bear and Tree Jumps 大意: 给定树,每步能走到距离不超过$k$的任意点,记$f(s,t)$为$s$到$t$的最少步数,求$\sum\limits_{s<t}f(s,t)$ 对于路径$(u,v)$, 假设距离为$d$, 那么贡献为$\lceil\frac{d}{k}\rceil=\frac{d+(-d\text{%}k+k)\text{%}k}{k}$ 也就是说枚举每条边的贡献算出总路径长, 再$O(nk^2)$的$dp$求出多余部分, 最后除以$k$即为答案 #in…
A. Vicious Keyboard time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only t…
FallDream打的AB都FFT了,只剩一个我打的C,没进前一百,之后看看马拉松复活赛有没机会呗. A. Voltage Keepsake 题目大意:n个东西,每个东西一开始有bi能源,每秒消耗ai能源,每秒可以给一个东西加p能源,秒可以为实数,问至多多少秒内所有东西能源一直为正.(n<=100,000) 思路:二分答案,随便check一下.不特判无解可能会炸精度. #include<cstdio> #include<algorithm> using namespace s…
http://codeforces.com/contest/967/problem/D 题目大意: 有n个服务器,标号为1~n,每个服务器有C[i]个资源.现在,有两个任务需要同时进行,令他为x1,x2. 运行任务的条件: ①每个服务器只能同时运行一个任务 ②任务可以同时分配到多个服务器中执行.假设任务x1分配到a个服务器中,则每个服务器都需要使用x1/a的资源(该资源可以为小数) 问能否满足以上条件,使得x1,x2同时在服务器中运行? 思路: 将所有服务器按照资源增序排列,定义dp(i)表示从…
B. Problems for Round 题目连接: http://www.codeforces.com/contest/673/problem/B Description There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficult…
A 模拟 B 发现对于每个连通块,只有为完全图才成立,然后就dfs C 构造 想了20分钟才会,一开始想偏了,以为要利用相邻NO YES的关系再枚举,其实不难.. 考虑对于顺序枚举每一个NO/YES,与前一个需要用的的字符串有k-1个交集,只多了一个string 于是只要保证k-1个string不同,只通过当前的string来影响答案, 若YES,开一个新的串: NO,则和第一个串一样,以此让这个相同串在下一次枚举中消失.. //怎么想到? 其实NO可能有多个相同名字,关系就很乱了,我们希望只有…
A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only t…
地址:http://codeforces.com/contest/807/problem/D 题目: D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya and Petya take part in a Codeforces round. The round las…
B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty,…
Description A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree that consists of n vertices, numbered 1 throu…
连接在这里,->点击<- A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and ther…