摘要:
简单并查集View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 100005int n, m;int f[maxn], father[maxn];int getanc(int a){ if (a == father[a]) return a; return father[a] = getanc(father[a]);}void merge(int a, int b){ fa 阅读全文
posted @ 2011-06-11 14:55
undefined2024
阅读(363)
评论(0)
推荐(0)
摘要:
题意:只有一艘船,能乘2人,船的运行速度为2人中较慢一人的速度,过去后还需一个人把船划回来,问把n个人运到对岸,最少需要多久。分析:我们设最快的为a,次快的为b,最慢的为z,次慢的为y。我们先考虑如何将y,z运到对岸,可以ab,a,yz,b,也可以ay,a,az,a。运送z不可能影响此4人之外的人,因为船只能乘2人,z要带也是带次慢的。那如果是单运z,然后x和y一起运呢?这种情况是不可能存在的。通过不等式可以证明如果单运y,z比一起运快,那么yx一起运绝对比单运y,x慢,所以不用考虑单运z必然单运y2a + y + z < 2b + a + z => 2a + x + y < 阅读全文
posted @ 2011-06-11 14:24
undefined2024
阅读(733)
评论(0)
推荐(0)
摘要:
最小生成树,由于是special judge 所以不用非得结果和样例一样View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxm 15005#define maxn 1005struct Edge{ int u, v, w;}edge[maxm], mst[maxm];int n, m, ecount, father[maxn 阅读全文
posted @ 2011-06-11 13:10
undefined2024
阅读(397)
评论(0)
推荐(0)
摘要:
组合数学View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;char st[15];int com(int n, int r){ if (n - r < r) r = n - r; int i, j, s = 1; for (i = 0, j = 1; i < r; ++i) { s *= (n - i); for (; j <= r && s % j == 0; 阅读全文
posted @ 2011-06-11 10:45
undefined2024
阅读(584)
评论(0)
推荐(0)