Codeforces 437B The Child and Set】的更多相关文章

题目链接:Codeforces 437B The Child and Set 開始是想到了这样的情况,比方lowbit之后从大到小排序后有这么几个数,200.100,60.50.S = 210.那先选了200肯定就不行了,所以写了个DFS.果断TLE.后来想了想lowbit之后的值都是最高位是1.其余位都是0的二进制数,所以上边的情况是不会出现的,至于原因我感觉我说不清楚.. #include <iostream> #include <cstdio> #include <ve…
题目链接:http://codeforces.com/contest/437/problem/B 题目意思:给出两个整数 sum 和 limit,问能否从1 - limit 这些数中选出一些数(注意:这些数最多只能取一次!),使得它们的lowbit 之和 等于 sum.不能则输出 -1. 这题总的来说比较直接.一开始犯了个比较傻的错误,以为除了2的幂以外,其他的 lowbit 都是1.还有一点需要注意的是,代码中 if (sum - t >= 0)  很重要!因为偶数的lowbit参差不齐,有可…
题目连接:Codeforces 437C  The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int MAX_N = 1000 + 10; int G[MAX_N][MAX_N]; struct…
题目链接:Codeforces 437E The Child and Polygon 题目大意:给出一个多边形,问说有多少种切割方法.将多边形切割为多个三角形. 解题思路:首先要理解向量叉积的性质,一開始将给出的点转换成顺时针.然后用区间dp计算.dp[i][j]表示从点i到点j能够有dp[i][j]种分割方法.然后点i和点j能否够做为分割线.要经过推断.即在i和j中选择的话点k的话,点k要在i,j的逆时针方. #include <cstdio> #include <cstring>…
题目链接:Codeforces 437A The Child and Homework 少看了一个条件,最后被HACK掉到203名,要不然就冲到100多一点了==.. 做这个题收获最大的是英语,A twice longer than B 表示 A >= 2 * B,A twice shorter than B表示 A * 2 <= B. #include <iostream> #include <cstring> #include <cstdio> #inc…
题目链接:Codeforces 437D The Child and Zoo 题目大意:小孩子去參观动物园,动物园分非常多个区,每一个区有若干种动物,拥有的动物种数作为该区的权值.然后有m条路,每条路的权值为该条路连接的两个区中权值较小的一个.假设两个区没有直接连接,那么f值即为从一个区走到还有一个区中所经过的路中权值最小的值做为权值.问,平均两个区之间移动的权值为多少. 解题思路:并查集+贪心.将全部的边依照权值排序,从最大的開始连接,每次连接时计算的次数为连接两块的节点数的积(乘法原理).…
Codeforces 437D The Child and Zoo 题目大意: 有一张连通图,每个点有对应的值.定义从p点走向q点的其中一条路径的花费为途径点的最小值.定义f(p,q)为从点p走向点q的所有路径中的最大花费.累加每一对p,q的f(p,q),并求平均值. 乍一看以为是对图的搜索,但搜索求和的过程肯定会超时.这一题巧妙的用到了并查集,因此做简单记录. 思路: 将边的权值定义为两点间的较小值,对边进行降序排序.排序后将每条边的两点进行并查集维护,由于排了序,所以可以保证两个点所属集合合…
Of course our child likes walking in a zoo. The zoo has n areas, that are numbered from 1 to n. The i-th area contains ai animals in it. Also there are m roads in the zoo, and each road connects two distinct areas. Naturally the zoo is connected, so…
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite sequence of Picks. Fortunately, Picks remembers how to repair the sequence. Initi…
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost,…