上一页 1 ··· 7 8 9 10 11 12 下一页

2012年6月7日

xmu 1337 后缀数组 + 暴力匹配

摘要: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1337题意:在一个串中求出一个长度为n的、重复了m次的子串(不能重叠)。思路:一直以为正解是后缀数组加其它高效的搜索方法。一水才知道,就是纯后缀数组+暴力匹配。先用后缀数组求出 sa,height两个数组的值,当height[i]=n时,取出当前子串,进行暴力匹配。囧~~~View Code #include<stdio.h>#include<string.h>#include<stdlib.h>const int maxn = 101000;int wn[m 阅读全文

posted @ 2012-06-07 13:44 aigoruan 阅读(244) 评论(0) 推荐(0)

pku 1743

摘要: View Code #include<stdio.h>#include<string.h>#include<stdlib.h>const int maxn = 20005;int wn[maxn],wa[maxn],wb[maxn],wv[maxn],a[maxn],sa[maxn],rank[maxn],height[maxn];char r[maxn];int n;int Max(int x,int y){return x>y?x:y;}int Min(int x,int y){return x>y?y:x;}int cmp(int *r,i 阅读全文

posted @ 2012-06-07 12:05 aigoruan 阅读(163) 评论(0) 推荐(0)

hdu 1403 简单后缀数组应用

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1403题意:给两串字符,求最长的公共子串。仔细想下就会想到后缀数组了。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>using namespace std;const int maxn = 220005;int wn[maxn],wa[maxn],wb[maxn],wv[maxn],a[maxn],sa[maxn],rank[maxn],height[maxn];char r[maxn];int 阅读全文

posted @ 2012-06-07 09:59 aigoruan 阅读(158) 评论(0) 推荐(0)

2012年6月5日

hdu 1195 Open the Lock 双广

摘要: //题目大意:求解开4位密码锁的最少步数.//<变化一次:加1;减1;邻位交换>思路:简单bfs能过,时间很高,双bfs好点。简单bfsView Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <queue>#include <algorithm>using namespace std;struct nd{ int num,st;};int hash[10000];int s,t;i 阅读全文

posted @ 2012-06-05 23:58 aigoruan 阅读(187) 评论(0) 推荐(0)

hdu3172 Virtual Friends

摘要: 很有意思的一道题:两个人成为朋友,他们就有关系,题目给出m句话,每一句是两个人,表示两个成为朋友,然后叫你求这与这两个人有关系的集合中有多少个人。以为stl过不了,结果过了,直接用map映射就好了,如果不在同一集合,就暴力合并(时间卡在这里)。注意一下这个题目的输入。View Code #include<stdio.h>#include<string.h>#include<string>#include<iostream>#include<map>#include<set>using namespace std;const 阅读全文

posted @ 2012-06-05 16:28 aigoruan 阅读(191) 评论(0) 推荐(0)

2012年6月3日

hdu 1599

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1599很有意思的floyd;#include<stdio.h>#include<string.h>const int N = 105;const int inf = 0xffffff;int as[N][N],bs[N][N],ans;void floyd(int n){ int k,i,j; for(k = 1; k <= n; ++ k){ for(i = 1; i <= k; ++ i) for(j = 1; j < i; ++ j) ... 阅读全文

posted @ 2012-06-03 20:59 aigoruan 阅读(184) 评论(0) 推荐(0)

2012年5月13日

“网宿科技杯”厦门大学第九届程序设计竞赛 现场决赛

摘要: “网宿科技杯”厦门大学第九届程序设计竞赛 现场决赛1342.篡改记忆抢劫事件文吉利他们用stl库暴力过了,很让人YY,我作了点小优化居然超时了(stl也有效率高的时候,orz~~),后来卡过去了。#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>int as[2006][1005],vis[2006];int judge(int m,int x,int y){ int i,k = 0; for(i = 0; i < m; ++ i) if(as[x][i 阅读全文

posted @ 2012-05-13 19:54 aigoruan 阅读(258) 评论(0) 推荐(0)

2012年4月27日

hdu 3779

摘要: 简单记忆化搜索View Code #include<stdio.h>#include<string.h>int as[1005],bs[1005],cs[2005],ok,n,m;char hash[1005][1005];void dfs(int x,int y,int z){ if(hash[x][y]||ok)return; if(z==n+m)ok = 1; hash[x][y] = 1; if(as[x]==cs[z]&&x<n)dfs(x+1,y,z+1); if(ok)return; if(bs[y]==cs[z]&& 阅读全文

posted @ 2012-04-27 16:19 aigoruan 阅读(141) 评论(0) 推荐(0)

hdu 1978

摘要: 记忆化搜索View Code #include<stdio.h>#include<string.h>int n,m;int as[105][105],hash[105][105];int dfs(int x,int y){ int i,j; if(x==n||y==m)return 0; if(hash[x][y]) return hash[x][y]; for(i = 0; i <= as[x][y]; ++ i) for(j = 0; j <= as[x][y]; ++ j) if((i+j)&&(i+x<n)&&( 阅读全文

posted @ 2012-04-27 16:02 aigoruan 阅读(207) 评论(0) 推荐(0)

hdu 1428

摘要: 记忆化搜索View Code #include<stdio.h>#include<string.h>#include<iostream>#include<queue>using namespace std;struct nd{ int x,y;};const long long inf = 0xfffffff;long long as[100][100],hash[100][100],dp[100][100];long long dx[] = {1,-1,0,0};long long dy[] = {0,0,1,-1};long long n;v 阅读全文

posted @ 2012-04-27 16:01 aigoruan 阅读(169) 评论(0) 推荐(0)

上一页 1 ··· 7 8 9 10 11 12 下一页

导航