![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
组合数学
ConwayTian
一切再来,为时未晚。
毁掉你人生的,其实是你内心的平庸,是你失去追求卓越的那个瞬间。
展开
-
ZOJ 2531 Traveller (Gray码)
Traveller Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge A traveller plans a round trip through n cities, where n is a power of 2, in which case we simply index them with n原创 2011-11-29 13:59:59 · 713 阅读 · 0 评论 -
POJ 1850 Code 统计问题
题意:存在下面的编码方式: a - 1 b - 2 ... z - 26 ab - 27 ... az - 51 bc - 52 ... vwxyz - 83681 其中字符串的长度逐渐增加,并且每一个字符串的字符只能是升序。例如b不能排在a的前面。 #include #include using namespace std; #define li原创 2012-04-05 20:23:49 · 817 阅读 · 0 评论 -
POJ 3252 Round Numbers 数字统计
题意:若一个数的二进制形式中0的个数不少于1的个数,那么就称这个数为round number,现在输入两个整数start,finish求在这两个数之间有多少个round number。 #include #include #define lint __int64 using namespace std; lint C ( int m, int n ) { if ( m <原创 2012-04-05 20:19:22 · 825 阅读 · 0 评论 -
POJ 3244 Difference between Triplets 公式转换
题意:两个三元组(x1,y1,z1),(x2,y2,z2)的距离如下定义 D = max {x1 − x2, y1 − y2, z1 − z2} − min {x1 − x2, y1 − y2, z1 − z2} 现在给你n个三元组,让你求出任意两个三元组的距离之和。 题解:公式转换非常有用,必须引起重视 先简化一下模型: 令a = x1-x2, b=y1-y2, c=z1-z2原创 2012-04-05 20:09:00 · 1273 阅读 · 0 评论 -
POJ 3286 How many 0's? / 2282 The Counting Problem 排列组合统计数字
比如算4123中有多少个2 按位统计,,,先算各位,,个位是2的情况有413种,,,因为各位左边可以0~412,,,而右边没有数字,,, 然后是十位,,,十位是2的有41*10 + 1*4种,,当左边从0~40时,,,右边可以从0~9,,,而左边为41时,,右边只能从0~3 然后是百位,,,,百位有4*100种,,,,即左边从0~3,,右边从0~99 千位有 1*1000,,,左边原创 2012-04-05 20:06:30 · 2079 阅读 · 2 评论 -
POJ 1430 Binary Stirling Numbers (斯特林数)
题意:给你n,k,求S(n,k) mod 2。 题解:没什么好说的,知道公式就好解决。C(z,w) = z! / [(w!) * (z-w)!],要判断奇偶性只需要统计一下分子分母的所含的因子2的个数。 #include #define lint __int64 lint getTwo ( lint x ) { lint cnt = 0, bit = 2; whi原创 2012-04-05 19:59:14 · 3006 阅读 · 0 评论 -
HDU 2461 Rectangles 容斥原理
题意:坐标系上有N个矩形,给出了他们的左下顶点和右上顶点。每次操作是对其中的R个矩形进行染色,然后要你输出这些被染色的矩形的面积之和(重叠部分不能重复计算)。 题解:标准的容斥原理。 #include #include #include #include using namespace std; struct Rectangle { int x1, y1, x2, y2;}; Rectang原创 2012-03-17 12:22:29 · 1146 阅读 · 0 评论 -
POJ 2356 Find a multiple / 3370 Halloween treats 鸽巢原理
题意:给定n个正整数,从中任意的选出一些数,使他们的和能够被n整除。 题解:《组合数学》P17 #include #include using namespace std; const int MAXN = 20000; int sum[MAXN], num[MAXN], flag[MAXN]; void print ( int s, int t ) { printf("%d\原创 2012-03-15 09:15:07 · 827 阅读 · 0 评论 -
HDU 1695 GCD 容斥原理+欧拉
题意:给你五个数a,b,c,d,k,令x ∈[a,b], y∈ [c,d]。求出有多少对(x,y)可以使gcd(x,y) == k。题中所有的a,b都等于1. 题解: 1. b /= k, d /= k, 这样就转换成求b,d之间有多少对互素。 2.不妨令b 3.当b #include #include #include #include using namespace std;原创 2012-03-17 11:15:06 · 899 阅读 · 0 评论 -
POJ 3487 The Stable Marriage Problem (稳定婚姻问题)
题意:http://poj.org/problem?id=3487 /*男生向女生求爱,男生最优稳定匹配*/ #include #include #include using namespace std; #define MAXN 50 int Mpref[MAXN][MAXN]; // Mpref[i][j]表示男生i第j偏爱的女生 int Wpref[MAXN][MAXN];原创 2011-11-30 23:30:52 · 1978 阅读 · 0 评论 -
ZOJ 3687 The Review Plan I 容斥原理/禁位排列
题意: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4970 题解: #include #include #include using namespace std; #define MOD 55566677 #define lint long long #define MAXN 52 int fa[MA原创 2013-05-26 23:25:09 · 1587 阅读 · 0 评论