上一页 1 ··· 5 6 7 8 9 10 11 12 下一页
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1241给一个二维图*:缺乏油的地方;@:有油的地方;当@与@之间相邻(水平,垂直,对角线八个方向都可),算同一个油田。求最多有多少个油田;#include <stdio.h>#include <string.h>#include<stdlib.h>#include <cmath>#include <iostream>using namespace std;#define MAXSIZE 103int dir[8][3]={{1,0},{-1,0},{ 阅读全文
posted @ 2011-03-22 10:48 CoderZhuang 阅读(173) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1240N表示三维图的大小(x,y,z为零到N-1),然后是一个三维图,最后是起点和终点的座标。答案输出N和从起点到终点走的步数。和hdu1253差不多的题目,并且本题不用剪技,直接BFS搜一遍就可以了。#include<stdio.h>#include<stdlib.h>#include<queue>#include<string.h>#include <iostream>using namespace std;char map[11][11][11 阅读全文
posted @ 2011-03-22 09:42 CoderZhuang 阅读(151) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/diy/contest_status.php?cid=1991给一个地图:'X': 障碍'S':狗的起始的位置'D':出口'.': 路要求刚好在T时间时到达出口,且路不可重走。输出是否能够完成。本题不宜用BFS,因为算的是恰好在T时间到达出口,并不是求最短时间。所以用DFS较好。当时间大于T时就不用考虑了,然后还要再奇偶性剪枝,进行优化。#include<stdio.h>#include<stdlib.h>#include<queue>#include 阅读全文
posted @ 2011-03-21 22:07 CoderZhuang 阅读(213) 评论(0) 推荐(0)
摘要: 一个三维图 ,0表示路,1表示障碍。在找由(0,0,0)到(A-1,B-1,C-1)的最短路,且在T之内。http://acm.hdu.edu.cn/showproblem.php?pid=1253#include<stdio.h>#include<stdlib.h>#include<queue>#include<string.h>#include <iostream>using namespace std;int map[51][51][51],visited[51][51][51];int dir[6][3]={{1,0,0},{ 阅读全文
posted @ 2011-03-21 16:41 CoderZhuang 阅读(165) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=3261给一串数组,数组最少含有k个相同子串,可重叠,求这样子串的最长长度。后缀数组求出height[],若连续k个height[]都大于mid,就可以了。当然要找最大的mid,这里可用二分查找.。关于后缀数组可以参考:http://hi.baidu.com/fhnstephen/blog/item/4b20757c37245d0429388a76.html#include <iostream>#include<stdio.h>#include<stdlib.h>using namespace std;co 阅读全文
posted @ 2011-03-19 14:36 CoderZhuang 阅读(161) 评论(0) 推荐(0)
摘要: Trie树就是字符树,其核心思想就是空间换时间。举个简单的例子。给你100000个长度不超过10的单词。对于每一个单词,我们要判断他出没出现过,如果出现了,第一次出现第几个位置。这题当然可以用hash来,但是我要介绍的是trie树。在某些方面它的用途更大。比如说对于某一个单词,我要询问它的前缀是否出现过。这样hash就不好搞了,而用trie还是很简单。现在回到例子中,如果我们用最傻的方法,对于每一个单词,我们都要去查找它前面的单词中是否有它。那么这个算法的复杂度就是O(n^2)。显然对于100000的范围难以接受。现在我们换个思路想。假设我要查询的单词是abcd,那么在他前面的单词中,以b,c 阅读全文
posted @ 2011-03-14 22:33 CoderZhuang 阅读(341) 评论(0) 推荐(0)
摘要: 转自百度百科http://baike.baidu.com/view/1364018.htm名称: sscanf() - 从一个字符串中读进与指定格式相符的数据.函数原型: Int sscanf( const char *, const char *, ...); int scanf( const char *, ...);头文件: #include<stdio.h>说明: sscanf与scanf类似,都是用于输入的,只是后者以键盘(stdin)为输入源,前者以固定字符串为输入源。 第一个参数可以是一个或多个 {%[*] [width] [{h | l | I64 | L}]ty. 阅读全文
posted @ 2011-03-14 21:35 CoderZhuang 阅读(445) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=3080不多说与poj3450 差不多,都是求几个字符串拥有的相同子串,并是最长的。不过这题要求子串长度不低于3,还有各个提供的字符串长度也都相等。所以是把做过的poj3450稍微改下,很给力0ms通过。Source CodeProblem: 3080User: 541780774Memory: 708KTime: 0MSLanguage: G++Result: AcceptedSource Code#include <stdio.h>#include <stdlib.h>#include<string.h> 阅读全文
posted @ 2011-02-28 14:20 CoderZhuang 阅读(141) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=3450给数个字符串,若这些字符串中拥有相同的子串,求最大长度的子串,长度相等取ASCII码小的。这题也是可以用KMP算法来解,用一个字符串枚举去匹配其它的串,找到一个最长的就可以了。当然时间要用得长一些了。Source CodeProblem: 3450User: 541780774Memory: 920KTime: 282MSLanguage: G++Result: AcceptedSource Code#include <stdio.h>#include <stdlib.h>#include<string. 阅读全文
posted @ 2011-02-28 13:47 CoderZhuang 阅读(167) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=3461题意:给两个字符串S,T;求S中最多含有多少个T。很显然直接贴个KMP算法就可以解决了。Source Code#include <stdio.h>#include <stdlib.h>#include<string.h>#include<iostream>using namespace std;int next[10001],n;struct { char str[1000001]; int len; }s,t; //主串s, 子串t。void get_next()//求模式串的“nex 阅读全文
posted @ 2011-02-27 01:08 CoderZhuang 阅读(113) 评论(0) 推荐(0)
上一页 1 ··· 5 6 7 8 9 10 11 12 下一页