A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you…
题目传送门 /* 贪心:每次把一个丢掉,选择最小的.累加求和,重复n-1次 */ /************************************************ Author :Running_Time Created Time :2015-8-1 13:20:01 File Name :A.cpp *************************************************/ #include <cstdio> #include <algori…
题目链接 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…
C. Appleman and a Sheet of Paper   Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q queries. Each query will hav…
题意:给了一棵树以及每个节点的颜色,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…
题目链接 A. Appleman and Easy Task time limit per test:2 secondsmemory limit per test:256 megabytesinput:standard inputoutput:standard output Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can…
称号: A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can…
吐槽:一辈子要在DIV 2混了. A,B,C都是简单题,看AC人数就知道了. A:如果我们定义数组为N*N的话就不用考虑边界了 #include<iostream> #include <string> #include <vector> #include<cstring> #include<cstdio> #include<cmath> #include<string> #include<algorithm>…
题目: C. Appleman and Toastman time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they s…
题目: B. Appleman and Card Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Applem…
B 树形dp 组合的思想. Z队长的思路. dp[i][1]表示以i为跟结点的子树向上贡献1个的方案,dp[i][0]表示以i为跟结点的子树向上贡献0个的方案. 如果当前为叶子节点,dp[i][0] = 1,(颜色为1,可以断开与父节点的连接,颜色为0,不断开,方案恒为1),dp[i][1] = co[i](i节点的颜色). 非叶子节点:将所有孩子节点的dp[child][0]乘起来为sum,孩子贡献为0的总方案. 当前颜色为0时, dp[i][1] += sum/dp[child][0]*dp…
数学家伯利亚在<怎样解题>里说过的解题步骤第二步就是迅速想到与该题有关的原型题.(积累的重要性!) 对于这道题,可以发现其实和huffman算法的思想很相似(可能出题人就是照着改编的).当然最后只是输出cost,就没必要建树什么的了.只要理解了huffman算法构造最优二叉树的思路,就按那么想就知道每个a[i]要加多少次了. 当然这道题没想到这些也可以找出规律的,就是一种贪心思想. #include<iostream> #include<cstdio> #include…
A: 这道题目还是非常easy的,做过非常多遍了.相似于分割木板的问题. 把全部的数放在一个优先队列里,弹出两个最大的,然后合并,把结果放进去.依次进行. #include <iostream> #include<stdio.h> #include<stdlib.h> #include<time.h> #include<vector> #include<algorithm> #include<string.h> #incl…
https://codeforces.com/contest/1118/problem/F1 #include<bits/stdc++.h> using namespace std; int n; vector<int> color; vector<vector<int> > tree; ,blue=; ; pair<){ ); ); ;i<tree[v].size();i++){ int u=tree[v][i]; if(u!=p){//避免回…
题目链接: http://codeforces.com/problemset/problem/258/B B. Little Elephant and Elections time limit per test2 secondsmemory limit per test256 megabytes 问题描述 There have recently been elections in the zoo. Overall there were 7 main political parties: one…
任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an undirected tree of nn vertices. Some vert…
题意: 给出一个具有N个点的树,现在给出两种操作: 1.get x,表示询问以x作为根的子树中,1的个数. 2.pow x,表示将以x作为根的子树全部翻转(0变1,1变0). 思路:dfs序加上一个线段树区间修改查询. AC代码: #include<iostream>#include<vector>#include<string.h>using namespace std;const int maxn=2e5+5;int sum[maxn<<2],lazy[…
B1. Character Swap (Easy Version) This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems. After struggling and failing many times, Ujan decided to tr…
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems. After struggling and failing many times, Ujan decided to try to clean up his house again. He…
题意:给你一组数\(a\),构造一个它的子序列\(b\),然后再求\(b_1-b2+b3-b4...\),问构造后的结果最大是多少. 题解:线性DP.我们用\(dp1[i]\)来表示在\(i\)位置,并且此时子序列的长度是奇数的情况,而\(dp2\)则是偶数情况,对于每个\(a_i\),\(dp[i]\)都可以选它或者不选,拿\(dp1[i]\)举例,如果选择\(a_i\),那么状态则可以从子序列中上一个位置转移过来,所以\(dp1[i]=dp2[i-1]+a[i]\),如果不选就是\(dp1[…
题意:有\(n\)本书,A和B都至少要从喜欢的书里面读\(k\)本书,如果一本书两人都喜欢的话,那么他们就可以一起读来节省时间,问最少多长时间两人都能够读完\(k\)本书. 题解:我们可以分\(3\)种情况来存,即: ​ 1.\(a=b=1\). 2.\(a=1,b=0\). 3.\(a=0,b=1\). 对于2和3来说,我们可以将他们排序,然后合并到一起,最后放到第1种情况中再排一次序,取前\(k\)个前缀和即可. 代码: int n,k; int t,x,y; int ans; vector…
题意:有一组数,每次操作可以将某个数移到头部或者尾部,问最少操作多少次使得这组数非递减. 题解:先离散化将每个数映射为排序后所对应的位置,然后贪心,求最长连续子序列的长度,那么最少的操作次数一定为\(n-len\). 感觉不好解释,直接上图,其实就是排序后它们一定是连续的,所以我们就求一个最长的连续的,然后s剩下的数移到头部尾部,贪心的想,这样一定是最优解. 代码: #include <iostream> #include <cstdio> #include <cstring…
题意:给你两个长度为\(n\)的01串\(s\)和\(t\),可以选择\(s\)的前几位,取反然后反转,保证\(s\)总能通过不超过\(3n\)的操作得到\(t\),输出变换总数,和每次变换的位置. 题解:构造题一定要充分利用题目所给的条件,对于\(s\)中的某一位i,假如它和\(t\)中的对应位置不同,我们先对前i个字符取反反转,然后再对第一个字符取反反转(就选了一个,反不反都无所谓),在取前i个位置取反反转,这样,我们就将第i个位置变换了,消耗了3次操作.这样就一定能保证在\(3n\)之内完…
Codeforces Round #421 (Div. 2) D. Mister B and PR Shifts 题意:给一个长度为\(n\)的排列,每次可以向右循环移位一次,计算\(\sum_{i=1}^{n}|p_i - i|\)的最小值,并求最小值是在第几次移动时取到的. 思路:我们注意到对于每个\(p_i\),其位置都取遍了\(1-n\),那么可以分成\(p_i > i\) 和 $p_i <= i $两种 对于前者 每次移动贡献-1,后者贡献+1,而且我们可以容易计算出每次移动后这两者…
Codeforces Round #598 (Div. 3)- E. Yet Another Division Into Teams - 动态规划 [Problem Description] 给你\(n\)个数,将其划分为多组,对于每个组定义其\(d\)值为 组内的最大值减最小值,问如何划分使得最终所有组的\(d\)值之和最小.每个组至少要保证有\(3\)个数. [Solution] 将所有值从小到大排序,然后我们知道最多有\(5\)个人划分到同一组中,如果有\(6\)个人,那么划分为两组一定比…
Educational Codeforces Round 84 (Div. 2) 读题读题读题+脑筋急转弯 = =. A. Sum of Odd Integers 奇奇为奇,奇偶为偶,所以n,k奇偶性要相同. 由求和公式得k个不同奇数组成的最小数为k2,所以n≥k2. #include <bits/stdc++.h> using namespace std; void solve(){ int n,k; cin>>n>>k; if((n-k)%2==0&&…
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate it n = int(raw_input()) s = "" a = ["I hate that ","I love that ", "I hate it","I love it"] for i in ran…
Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393…
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输出”#Color”,如果只有”G”,”B”,”W”就输出”#Black&White”. #include <cstdio> #include <cstring> using namespace std; const int maxn = 200; const int INF =…
 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256…