摘要: Trie树,每个结点记录其下面分支的单词总数。View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;struct Node{ Node *next[26]; int count;} trie[100000];int ncount;void ins(Node *proot, char *st){ proot->count++; if (st[0] == '\0') return; 阅读全文
posted @ 2011-06-05 17:58 undefined2024 阅读(364) 评论(0) 推荐(0)
摘要: 题意:有一个矩阵,某些格有人,某些格有房子,每个人可以上下左右移动,问给每个人进一个房子,所有人需要走的距离之和最小是多少。分析:最小费用最大流每个人一个点,每个房子一个点,每个人到所有房子加容量为1费用为二者距离的边,源到所有人加容量为1费用为0的边,所有房子到汇加容量为1费用为0的边。因为没有初始化ne,wa了两次。渐渐开始理解网络流的题型了,是一种可以自由分配,求最优分配方案的题。View Code #include #include #include #include #include usingnamespace std;#define inf 0x3f3f3f3f#define N 阅读全文
posted @ 2011-06-05 17:30 undefined2024 阅读(726) 评论(0) 推荐(0)
摘要: 简单题View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#define maxn 405char a[maxn], b[maxn], c[maxn];bool found;void work(int ap, int bp, int cp){ if (found) return; if (cp == -1) { found = true; return; } if (ap >= 0 & 阅读全文
posted @ 2011-06-05 16:05 undefined2024 阅读(268) 评论(0) 推荐(0)
摘要: 简单题View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;char st[20];int main(){ //freopen("t.txt", "r", stdin); gets(st); int ans = 0; int pos = 0; for (int i = 0; i < 10; i++) if (st[i] == '?') p 阅读全文
posted @ 2011-06-05 15:55 undefined2024 阅读(241) 评论(0) 推荐(0)
摘要: 题意:求凸包直径。分析:用graham按纵坐标序,再用旋转卡壳法。但是模板我并没有完全理解,为什么要用点到直线的距离呢View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <algorithm>usingnamespace std;#define maxn 50005struct Xpoint{ int x, y;} pnt[maxn], res[maxn];int n;bool mult(Xpoint sp 阅读全文
posted @ 2011-06-05 15:35 undefined2024 阅读(721) 评论(0) 推荐(0)
摘要: 题意:给出一个有向图,求一共有多少个点,满足这样的条件:所有其它的点都可以到达这个点。分析:强连通分支+缩点,然后统计每个强连通分支的出度,如果只有一个为0,则输出其内部点的个数,如果有多个为0,说明没有答案。View Code #include #include #include #include usingnamespace std;#define maxn 10005#define maxm 50005struct Edge{ int v, next;} edge[maxm], opedge[maxm];int n, m, head[maxn], ophead[maxn], nco... 阅读全文
posted @ 2011-06-05 00:21 undefined2024 阅读(906) 评论(0) 推荐(0)