传送门 题意: 这道题说的是在一颗有两种颜色的树上,每操作一个节点,可以改变这个节点颜色和相邻同色节点的颜色.问最少操作次数,使得树上颜色相同. 思路: 先缩点,把相同的颜色的相邻节点缩在一起.再求出树的最长直径S(边的个数),答案就是(S + 1)/ 2: 因为对于一条链,我们可以从中间向两边交换改变. #include <bits/stdc++.h> #define pb push_back using namespace std; ; vector<int>mp[MAXN],…
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…
题目链接: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…
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…
题意: 给一颗树 每个节点有黑白2色 可以使一个色块同事变色,问最少的变色次数. 思路: 先缩点 把一样颜色的相邻点 缩成一个 然后新的树 刚好每一层是一个颜色. 最后的答案就是树的直径/2 不过我用的树上的dp,强行求了以每个点为根时树的深度 答案就是最小的深度-1 具体见代码: + ; int n; int color[maxn]; int pa[maxn]; vector<int> G[maxn], G2[maxn]; void init() { scanf("%d"…
题目链接: Anton and Tree 题意:给出一棵树由0和1构成,一次操作可以将树上一块相同的数字转换为另一个(0->1 , 1->0),求最少几次操作可以把这棵数转化为只有一个数字的一棵数. 题解:首先一次可以改变一片数字,那么进行缩点后就变成了每次改变一个点.缩完点后这棵数变成了一棵相邻节点不同,0和1相交叉的一棵树.然后一棵树的直径上就是 这种情况,相当于从中间开始操作,总共操作(L+1)/2次.关于其他的分支一定会在直径的改变过程中完成改变. #include<bits/s…
D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to…
C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions. Anton has a…
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6. Anton's favorite integers are 32 and 256. He decide…
A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play chess, and so does his friend Danik. Once they have played n games in a row. For each game it's known who was the winner - Anton or Danik. None of th…
题目链接: http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test4 secondsmemory limit per test256 megabytes 问题描述 Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that pla…
题目链接:http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Anton likes to play chess. Also, he likes to do programming. That is why…
题目链接:http://codeforces.com/contest/734/problem/C C. Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Anton is playing a very interesting computer game, but now he i…
C. Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next…
题意: 给你n对 b[i], c[i], 让你求a[i],不存在输出-1 b[i] = (a[i] and a[1]) + (a[i] and a[2]) + (a[i] and a[3]) +...+ (a[i] and a[n]); c[i] = (a[i] or a[1]) + (a[i] or a[2]) + (a[i] or a[3]) +...+ (a[i] or a[n]); and 和 or 是按位与 或 思路: (a and b) + (a or b) = (a + b) 证明…
题意:给你含有\(n\)个节点,\(n-1\)条边的树,以及\(m\)个质数和\(1\),你需要在这\(m\)个质数和一个\(1\)选择数(质数只能选一次,\(1\)可以多选)给\(n-1\)条边赋值,求所有简单路径的边权和. 题解:很简单,对于每条边,我们看它左右有多少个点,右边有多少点,左边点数x右边点数就是包含这条边的简单路径数,也就是说这条边权要计算的次数,我们一定会把最大的边权赋给简单路径数最多的边,所以我们可以直接dfs求每个点的子节点个数\(son[u]\)(右边的点数),那么\(…
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再看自己的代码发现有清晰的思维是多重要 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include…
A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lucky_ji: 水题,模拟统计A和D的数目比较大小输出结果即可 Tags: Implementation B.Anton and Digits Problems: 给定k2个2,k3个3,k5个5及k6个6,可以组成若干个32或256,求所有方案中Sigma的最大值 Analysis: lucky_ji: 同…
前言 初入acm的新手,打算在cf混.这几天没有比赛,就做了个最新的Virtual participation.虽然说div2比较简单,但还是被虐得体无完肤...Orz.两个小时,共6道题.最后只AC了AB两道,花了20分钟,剩下的100分钟也不知道哪去了(逃 A.B两道水题没什么说的.那我们从C题开始吧 C. Anton and Making Potions 题意 制作n瓶药水,初始时每制作一瓶花费x秒,有两类法术,第一类(包含m个法术)使制作每瓶药的时间由x变为a[i] (a[i] < x)…
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…
https://codeforces.com/contest/1059/problem/E 题意 给出一棵树,每个点都有一个权值,要求你找出最少条链,保证每个点都属于一条链,而且每条链不超过L个点 和 每条链的权值和不超过S 题解 对于儿子来说,父亲节点只有一个,所以没有决策点.可以从下往上处理出,每个节点最远能爬到那个节点(过程就是倍增) 然后从下往上贪 (选择往上走的远的子节点) #include<bits/stdc++.h> #define ll long long #define pb…
题目链接:https://codeforces.com/contest/1244/problem/D 题意:给你一个树,让你把树上的每个节点染成三种颜色,使得任意三个互相相邻的节点颜色都不一样(意思是如果两个节点相邻,那么与这两个节点相邻的节点的颜色得和这两个节点都不一样).这里给出每个节点染成三种颜色的代价,让我们求全部染色代价最小的方案与最小代价. 解析:如果一个点的度数大于等于3,那么肯定没有方案.所有这个树一定只是一条链,我们从度数为1的点开始dfs,把这条链存在数组里,就相当于我们只需…
B. Anton and Lines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/B Description The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforc…
D. Anton and School - 2 题目连接: http://codeforces.com/contest/785/problem/D Description As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn differ…
B. Anton and Lines   The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necess…
E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/problem/E Description Anton loves transforming one permutation into another one by swapping elements for money, and Ira doesn't like paying for stupid game…
C. Anton and Fairy Tale 题目连接: http://codeforces.com/contest/785/problem/C Description Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale: "Once upon a time, there liv…
B. Anton and Classes 题目连接: http://codeforces.com/contest/785/problem/B Description Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes. Anton has n variants when he wil…
A - Anton and Polyhedrons 题目连接: http://codeforces.com/contest/785/problem/A Description Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: Tetrahedron. Tetrahedron has 4 triangular face…
A. Anton and Danik time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Anton likes to play chess, and so does his friend Danik. Once they have played n games in a row. For each game it's known…