E. Ostap and Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a conn…
A. Ostap and Grasshopper 题面 On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he p…
A - Ostap and Grasshopper zz题能不能跳到  每次只能跳K步 不能跳到# 问能不能T-G  随便跳跳就可以了  第一次居然跳越界0.0  傻子哦  WA1 n,k = map(int,input().split()) s = input() i = 0 st = -1 def jump(st): while(st<n): st+=k if(st>=n or s[st]=='#'): return "NO" if(s[st]=='T' or s[st…
B. Invariance of Tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/576/problem/B Description A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. W…
D. Taxes 题目链接 http://codeforces.com/contest/735/problem/D 题面 Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated a…
C. Tennis Championship 题目链接 http://codeforces.com/contest/735/problem/C 题面 Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will fo…
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move…
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据,看看有没有结论. 2 3 4 5 6 7 8 9 10 11 12 (人数) 1 2 2 3 3 3 4 4 4 4 4 (比赛数) 发现比赛数的增长成斐波那契.维护一个前缀和即可. #include <bits/stdc++.h> #define ll long long using names…
C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There w…
题目链接:Taxes D. Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to…
C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There w…
题目链接: A:Ostap and Grasshopper B:Urbanization C:Tennis Championship D:Taxes 分析:这场第一二题模拟,三四题数学题 A. 直接模拟即可 B. 排序从大到小取n1个数到城市1,n2个数到城市二,n1<=n2 C. 递推.斐波拉契数列 dp[i] 表示赢i场比赛需要多少人, 则 dp[0] = 1,dp[1] = 2,dp[3] = dp[1] +dp[0],  dp[ans] = dp[ans-1] + dp[ans-2]一次…
A.= = B. 题意:给出n个数和n1和n2,从n个数中分别选出n1,n2个数来,得到n1个数和n2个数的平均值,求这两个平均值的最大和 分析:排个序从后面抽,注意先从末尾抽个数小的,再抽个数大的 C. 题意:有n个队伍比赛,每两个队伍比赛结束后输的人退场,赢的人场次增加1,现在由你来设计比赛顺序(比赛的两个队伍的场次之差不能大于1),使得最后胜利的冠军队伍的参加场次最多,输出这个场次 分析:先开始的贪心错了,以为就是简单的每次对半打 设f(i)表示打i场最少需要f(i)个队伍 f(i)=f(…
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了手速与精准的竞争--(遗憾,如果参加了一定可以上分的吧orz) A题: 先判断起点和终点的距离是否被每次跳的距离整除,如果不整除就到不了.再检验跳跃过程中的落点是否均合法即可. #include<stdio.h> #include<bits/stdc++.h> #include <…
题意:纳税额为金额的最大因数(除了本身).为了逃税将金额n分为n1+n2+.......问怎样分纳税最少. 哥德巴赫猜想: 任一大于2的偶数都可写成两个质数之和. 质数情况: 任何大于5的奇数都是三个素数之和 因此,如果n是偶数,结果就是2. 如果n是奇数.奇数只能拆成一奇一偶.分为2种情况.一偶是2时,那么如果一奇是质数,结果为2.如果一奇不是质数,那么结果至少为3,由于哥德巴赫猜想,3一定可行的,因此结果就是3. 一偶不是2时,一偶至少要交税2,一奇至少交税1,同样由猜想,结果为3. //#…
时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 131072K,其他语言262144K64bit IO Format: %lld 题目描述 Forever97与未央是一对笔友,他们经常互相写信.有一天Forever97去邮局寄信,发现邮局的收费方式变成了按字收费,收取的费用为总字数除了其自身以外的最大因子.虽然Forever97是一个有情调的人,但他不想因新收费方式而破财,所以他打算把信分成几份寄出去来减少邮费.已知Forever97写的信共有n个字,可以拆成无数封信,也可以不拆,…
E. Anton and Tree 题目连接: http://codeforces.com/contest/734/problem/E Description Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are n vertices in the tree, each of them is painted bla…
A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure…
https://codeforces.com/contest/1059/problem/E 题意 给出一棵树,每个点都有一个权值,要求你找出最少条链,保证每个点都属于一条链,而且每条链不超过L个点 和 每条链的权值和不超过S 题解 对于儿子来说,父亲节点只有一个,所以没有决策点.可以从下往上处理出,每个节点最远能爬到那个节点(过程就是倍增) 然后从下往上贪 (选择往上走的远的子节点) #include<bits/stdc++.h> #define ll long long #define pb…
http://codeforces.com/contest/463/problem/E 给出一个总节点数量为n的树,每个节点有权值,进行q次操作,每次操作有两种选项: 1. 询问节点v到root之间的路径上的各个节点,求满足条件 gcd(val[i], val[v]) > 1 的 距离v最近的节点的下标. 2. 将节点v的值求改为w. 暴力居然过了! #include <iostream> #include <cstdio> #include <cstring>…
题目链接:http://codeforces.com/problemset/problem/698/B题意:告诉你n个节点当前的父节点,修改最少的点的父节点使之变成一棵有根树.思路:拆环.题解:http://codeforces.com/blog/entry/46148代码: #include <cstdio> ; int f[maxn], vis[maxn], n, s, cnt, idx; int Find(int x) { vis[x] = ++ idx; while (!vis[ f[…
题目链接:http://codeforces.com/contest/734/problem/E E. Anton and Tree time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Anton is growing a tree in his garden. In case you forgot, the tree is a…
题目链接:http://codeforces.com/contest/699/problem/D D. Fix a Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A tree is an undirected connected graph without cycles. Let's consider a root…
题目链接:https://codeforces.com/contest/1244/problem/D 题意:给你一个树,让你把树上的每个节点染成三种颜色,使得任意三个互相相邻的节点颜色都不一样(意思是如果两个节点相邻,那么与这两个节点相邻的节点的颜色得和这两个节点都不一样).这里给出每个节点染成三种颜色的代价,让我们求全部染色代价最小的方案与最小代价. 解析:如果一个点的度数大于等于3,那么肯定没有方案.所有这个树一定只是一条链,我们从度数为1的点开始dfs,把这条链存在数组里,就相当于我们只需…
题意: 给一颗树 每个节点有黑白2色 可以使一个色块同事变色,问最少的变色次数. 思路: 先缩点 把一样颜色的相邻点 缩成一个 然后新的树 刚好每一层是一个颜色. 最后的答案就是树的直径/2 不过我用的树上的dp,强行求了以每个点为根时树的深度 答案就是最小的深度-1 具体见代码: + ; int n; int color[maxn]; int pa[maxn]; vector<int> G[maxn], G2[maxn]; void init() { scanf("%d"…
题目链接 2了,差点就A了...这题真心不难,开始想的就是暴力spfa就可以,直接来了一次询问,就来一次的那种,TLE了,想了想,存到栈里会更快,交又TLE了..无奈C又被cha了,我忙着看C去了...这题,是我一个地方写错了..top = 0的时候会死循环吗?貌似不会把,反正我加了这个判断,就A了,可能优化了一下把. #include <cstring> #include <cstdio> #include <string> #include <iostream…
题意:给了一棵树以及每个节点的颜色,1代表黑,0代表白,求将这棵树拆成k棵树,使得每棵树恰好有一个黑色节点的方法数 解法:树形DP问题.定义: dp[u][0]表示以u为根的子树对父亲的贡献为0 dp[u][1]表示以u为根的子树对父亲的贡献为1 现在假设u为白色,它的子树有x,y,z,那么有 dp[u][1]+=dp[x][1]*dp[y][0]*dp[z][0]+dp[x][0]*dp[y][1]*dp[z][0]+dp[x][0]*dp[y][0]*dp[z][1] dp[u][0]+=d…
E. Anton and Tree time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are n v…
第一次正式参加常规赛想想有些小激动的呢 然后第一题就被hack了 心痛 _(:зゝ∠)_ tle点在于越界 因此结束循环条件从乘变为除 done //等等 这题没过总评 让我静静........ //改天再来改吧....... #include <cstdio> int main() { long long l, r, k; scanf("%I64d%I64d%I64d", &l, &r, &k); if(k > r) puts("-…
题目链接 D. Appleman and Tree time limit per test :2 seconds memory limit per test: 256 megabytes input :standard input output:standard output Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices a…