2012年5月13日
摘要:
/** 求简单多边形面积 */ #include <cstdio>#include <iostream>using namespace std;const int N = 105;struct point { int x; int y;}p[N];int crossProd(point A, point B) { return A.x*B.y - A.y*B.x;}int compArea(int n) { p[n] = p[0]; int area = 0; for (int i=0; i<n; ++i) area += crossProd(p[i], p[i+
阅读全文
posted @ 2012-05-13 07:36
Try86
阅读(166)
推荐(0)
摘要:
/** 题意:求最多有多少个点共线 * 思路:枚举两点求直线,枚举有多少个点在直线上 */#include <cstdio>#include <iostream>using namespace std;const int N = 705;struct point { int x; int y;}p[N];int solve(int n) { int a, b, c, counts, ans = -1; for (int i=0; i<n; ++i) { for (int j=i+1; j<n; ++j) { a = p[j].y - p[i].y; //一般
阅读全文
posted @ 2012-05-13 07:26
Try86
阅读(279)
推荐(0)
2012年5月12日
摘要:
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <iostream> 5 6 using namespace std; 7 8 const int N = 205; 9 const int L = 10005; 10 const int M = 100010; 11 12 int ans[5]; 13 char pat[N], str[L]; 14 struct node { 15 int n; 16 node *prefix; 17 node *.
阅读全文
posted @ 2012-05-12 20:20
Try86
阅读(325)
推荐(0)
2012年5月9日
摘要:
参考:http://www.cppblog.com/mythit/archive/2009/04/21/80633.html 1 /* 2 * AC自动机 3 */ 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <iostream> 8 9 using namespace std;10 11 const int N = 51;12 const int L = 500001;13 const int M = 1000001;14 15 char pa
阅读全文
posted @ 2012-05-09 13:03
Try86
阅读(189)
推荐(0)
2012年5月8日
摘要:
1 /* 2 * 并查集+字典树 3 */ 4 5 #include <cstdio> 6 #include <cstdlib> 7 #include <cstring> 8 #include <iostream> 9 10 using namespace std;11 12 const int N = 21;13 const int M = 200005;14 15 int cs;16 int parent[M];17 char strA[N], strB[N];18 struct node {19 int c;20 node *child[5
阅读全文
posted @ 2012-05-08 18:27
Try86
阅读(376)
推荐(0)
摘要:
1 /* 2 * 字典树 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 #include <iostream> 8 9 using namespace std;10 11 const int N = 11;12 13 bool yes;14 char str[N];15 struct node {16 bool flag;17 node *child[10];18 node() {19 flag = false;20 for (int i=...
阅读全文
posted @ 2012-05-08 07:11
Try86
阅读(141)
推荐(0)
摘要:
1 /* 2 * 字典树 3 * 思路:把所有单词建成一棵字典树,然后把每个分成两部分,判断这两部分是否在树中 4 * 是,就符合条件。 5 */ 6 7 #include <cstdio> 8 #include <cstdlib> 9 #include <cstring>10 #include <iostream>11 12 using namespace std;13 14 const int N = 16;15 const int M = 50005;16 17 char strL[N], strR[N], dic[M][N]; 18 st
阅读全文
posted @ 2012-05-08 07:03
Try86
阅读(739)
推荐(0)
2012年5月7日
摘要:
1 /* 2 * 字典树 3 */ 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <iostream> 8 9 using namespace std;10 11 const int N = 11;12 13 char str[N];14 struct node {//节点数据 15 int c; //统计前缀个数 16 node *child[26];17 node() {//初始化 18 c = 1;19 for (int i...
阅读全文
posted @ 2012-05-07 21:52
Try86
阅读(124)
推荐(0)
摘要:
1 /* 2 * kmp 3 */ 4 #include <cstdio> 5 #include <iostream> 6 7 using namespace std; 8 9 const int N = 10005;10 const int M = 1000005;11 12 int next[N];13 char pat[N], str[M];14 15 void indexNext() {16 int k = 0;17 next[1] = 0;18 for (int i=2; pat[i]; ++i) {19 while (k && pat...
阅读全文
posted @ 2012-05-07 17:41
Try86
阅读(184)
推荐(0)
摘要:
摘自:http://www.cnblogs.com/wuyiqi/archive/2012/01/05/2313746.html题意:求给定字符串含前缀的数量abab前缀为aababaabababab中共有六个子串是前缀a a ab ab aba abab所以答案为6利用kmp中的匹配原理可以完美的解决此题a---------d----- -----a---------d i j如上所示,假设两串字符完全相等,next[j]=i,代表s[1...i]==sum[j-i+1....j],这一段其实就是前缀i~j之间已经不可能有以j结尾的子串是前缀了,不然next【j】就不是 i 了设dp【i】:
阅读全文
posted @ 2012-05-07 12:56
Try86
阅读(1008)
推荐(0)