上一页 1 ··· 7 8 9 10 11 12 13 14 15 下一页
摘要: 有n个家庭,m个房间,一个房间只能两个家庭住。求最大匹配。 比较标准的二分图问题。先初始化把可能的家庭建边,然后跑一边匈牙利算法。 最后的答案是最大匹配数/2,因为建图时有重复。 #include <cstdio> #include <algorithm> #include <cstring> #i 阅读全文
posted @ 2016-02-17 23:19 Helica 阅读(274) 评论(0) 推荐(0) 编辑
摘要: 有两段字符串,第一段的尾和第二段的头可能重合。问有多少种组合的可能。 需要理解一下next数组的意义。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 10 阅读全文
posted @ 2016-02-17 23:15 Helica 阅读(168) 评论(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 阅读(184) 评论(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 阅读(191) 评论(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 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 模板题 对于每修复一台终端,就遍历所有其他已修复的终端,如果距离在d之内,就union。 之后看是否在一个并查集中。 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int N,D,pos[ 阅读全文
posted @ 2016-02-02 00:01 Helica 阅读(163) 评论(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 阅读(184) 评论(0) 推荐(0) 编辑
摘要: FJ对以后的每一天会花mi块钱,他想把这些天分成M个时段,然后每个时段的花费和最小。 二分答案,如果加上这天还没有达到mid,就加上它。之后看分成的时段是否大于M #include <cstdio> #include <algorithm> using namespace std; int n,m, 阅读全文
posted @ 2016-01-31 19:08 Helica 阅读(388) 评论(0) 推荐(0) 编辑
摘要: 一条河里有一串石头,给出石头间的间距,让你去掉m个石头,使最短间距最大。 二分答案,对于每一种mid,判断要不要删除这块石头。然后逼近答案。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; 阅读全文
posted @ 2016-01-31 19:06 Helica 阅读(316) 评论(0) 推荐(0) 编辑
摘要: 一根细棒升温时会变长,在两面墙中间,会变成一个弓形。 给出变长后的长度,求新的细棒中心与没伸长时的中心的距离。 简单的数学推导后就可以二分答案了,一开始没完全掌握二分的姿势,wa了好多。而且poj double输出要用%f,用%lf就wa了。 #include <cstdio> #include < 阅读全文
posted @ 2016-01-31 19:03 Helica 阅读(233) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 下一页