上一页 1 ··· 7 8 9 10 11 12 13 14 15 16 下一页
摘要: 依次考虑一个数的倍数,两个数的倍数(lcm),三个数的倍数(lcm)。。。 会发现有这么一个规律,奇数个数时要加上情况数,偶数个数时要减去情况数。 一种只有10个数,用二进制枚举所有情况即可。 #include <cstdio> #include <algorithm> #include <cstr 阅读全文
posted @ 2016-02-17 23:23 Helica 阅读(267) 评论(0) 推荐(0)
摘要: 有n个家庭,m个房间,一个房间只能两个家庭住。求最大匹配。 比较标准的二分图问题。先初始化把可能的家庭建边,然后跑一边匈牙利算法。 最后的答案是最大匹配数/2,因为建图时有重复。 #include <cstdio> #include <algorithm> #include <cstring> #i 阅读全文
posted @ 2016-02-17 23:19 Helica 阅读(277) 评论(0) 推荐(0)
摘要: 有两段字符串,第一段的尾和第二段的头可能重合。问有多少种组合的可能。 需要理解一下next数组的意义。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 10 阅读全文
posted @ 2016-02-17 23:15 Helica 阅读(175) 评论(0) 推荐(0)
摘要: 很水的模拟题,拿数组搞就好了。 注意边界的地方不要算重。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int N,T,M; int save[10000]; char str[1000] 阅读全文
posted @ 2016-02-17 23:04 Helica 阅读(193) 评论(0) 推荐(0)
摘要: 维护一个relation数组,保留着此元素和根元素之间的性别关系。之后就可以判断gay了。 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int maxn=2010; int 阅读全文
posted @ 2016-02-02 00:07 Helica 阅读(201) 评论(0) 推荐(0)
摘要: 记录元素个数的并查集。 利用sz数组保存并查集的大小。每次union时,把小的集合并到大的中去,并更新sz数组。 #include <cstdio> #include <algorithm> using namespace std; int n,m,k; int fa[30010],sz[30010 阅读全文
posted @ 2016-02-02 00:03 Helica 阅读(216) 评论(0) 推荐(0)
摘要: 模板题 对于每修复一台终端,就遍历所有其他已修复的终端,如果距离在d之内,就union。 之后看是否在一个并查集中。 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int N,D,pos[ 阅读全文
posted @ 2016-02-02 00:01 Helica 阅读(167) 评论(0) 推荐(0)
摘要: 模板题。 #include <cstdio> #include <cstring> using namespace std; const int MOD = 10000; int N; struct matrix { int m[2][2]; }ans,base; matrix multi(matr 阅读全文
posted @ 2016-01-31 21:47 Helica 阅读(189) 评论(0) 推荐(0)
摘要: FJ对以后的每一天会花mi块钱,他想把这些天分成M个时段,然后每个时段的花费和最小。 二分答案,如果加上这天还没有达到mid,就加上它。之后看分成的时段是否大于M #include <cstdio> #include <algorithm> using namespace std; int n,m, 阅读全文
posted @ 2016-01-31 19:08 Helica 阅读(398) 评论(0) 推荐(0)
摘要: 一条河里有一串石头,给出石头间的间距,让你去掉m个石头,使最短间距最大。 二分答案,对于每一种mid,判断要不要删除这块石头。然后逼近答案。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; 阅读全文
posted @ 2016-01-31 19:06 Helica 阅读(326) 评论(0) 推荐(0)
上一页 1 ··· 7 8 9 10 11 12 13 14 15 16 下一页