上一页 1 ··· 5 6 7 8 9 10 11 12 13 14 下一页
  2011年9月5日
摘要: poj 1562题目大意:给出一个地图,‘@’表示存在石油,‘*’表示空白,求出共有多少个油田,相邻的或者是对角线相邻算同一个油田解决:bfs或者是dfs,本题采用dfs#include <iostream>using namespace std;int m,n;const int N=105;char map[N][N];int dx[]={1,-1,0,0,1,1,-1,-1};int dy[]={0,0,1,-1,1,-1,1,-1};void dfs(int x,int y){ map[x][y]='*'; for(int i=0;i<8;i++) { 阅读全文
posted @ 2011-09-05 20:32 猿类的进化史 阅读(200) 评论(0) 推荐(0) 编辑
摘要: poj 1111题目大意:给出一个地图,‘x’代表有效区域,‘.’代表空白区域,在给出鼠标点击的位置,求鼠标点击位置的有效区域的周长是多大解决:BFS,关键是如何求周长的问题,由于一个‘x’,有四个面,如果该格子四周周围有n个面(只需统计四周,而不是八个方向都需要统计),则这个‘x’的有效周长是4-n,如何知道周围有多少个面,只需要在四个面遍历的时候记录下就行了,用了一个vis数组表示i,j这个地方有没有‘x’存在,vis数组是一直不变的而BFS中访问过的用‘.’,以免重复访问。#include <iostream>#include <cstring>#include 阅读全文
posted @ 2011-09-05 19:57 猿类的进化史 阅读(504) 评论(0) 推荐(0) 编辑
  2011年9月4日
摘要: poj 1088题目大意:解决:记忆化搜索 dfs#include <iostream>using namespace std;#define D "%d" #define _S scanf const int N=105;int map[105][105];int dp[105][105];bool vis[105][105];int m,n;int dx[]={1,-1,0,0};int dy[]={0,0,-1,1};int dfs(int x,int y){ if(dp[x][y] > 0)return dp[x][y]; for(int i=0; 阅读全文
posted @ 2011-09-04 22:24 猿类的进化史 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 题目大意:给出一个地图,地图中有湖水区和干燥区,求出湖水区的最大面积解决:纯BFS,不用剪枝#include <iostream> #include <queue>using namespace std;int map[105][105];int n,m,k;int dx[]={1,-1,0,0};int dy[]={0,0,1,-1};struct node { int x,y; node(){} node(int xx,int yy):x(xx),y(yy){}};int bfs(int x,int y){ queue<node> q; node t,t 阅读全文
posted @ 2011-09-04 18:00 猿类的进化史 阅读(269) 评论(0) 推荐(0) 编辑
摘要: -----------------------------最优化问题-----------------------------------------------------------常规动态规划 SOJ1162 I-Keyboard SOJ1685 ChopsticksSOJ1679 GangstersSOJ2096 Maximum Submatrix SOJ2111 littleken bgSOJ2142 Cow Exhibition SOJ2505 The County FairSOJ2818 QQ音速 SOJ2469 Exploring Pyramids SOJ1833 Base N 阅读全文
posted @ 2011-09-04 10:46 猿类的进化史 阅读(1543) 评论(0) 推荐(0) 编辑
摘要: poj 3278题目大意:给出坐标中人的位置和牛的位置,然后牛不动,让你按照给定的策略(走一秒,退一退,走二倍当前的时间)去到牛的身边,求最小步子数解决:DFS,分析若一开始牛在人的身后,只有往后退的份了,所以加一个判断条件最好#include <iostream>#include <queue>using namespace std;int n,k;struct node{ int pos,step; node(int p,int s){pos=p;step=s;} node(){}};bool inq[200005];int bfs(){ node t; queue 阅读全文
posted @ 2011-09-04 10:31 猿类的进化史 阅读(310) 评论(0) 推荐(0) 编辑
  2011年9月3日
摘要: 将网上和课件的hash做个小结1、解决冲突是hash表的关键,冲突越少,hash表的效率越高2、设计hash函数方法,分别介绍整数和字符串的hash函数一、整数的hash函数(1)最常见的是直接取余数法,h(k)=k mod M,M表示hash表的容量,此处应注意M的选取,M若选不好,很容易出现同义词。一般情况下,可以选M为素数或者不包含小于20的质因数的合数。(2)平方取中法,对关键字k平方,中间几位数k的每一位的影响最大,把关键字k平方后,取出中间r位作为哈希函数h(k)的值,这时需要容量M=2的r次方,一般情况是将关键字转化为二进制,平方后取中间r位作为哈希地址即h(k)例如:r=4,k 阅读全文
posted @ 2011-09-03 23:11 猿类的进化史 阅读(247) 评论(0) 推荐(0) 编辑
  2011年9月2日
摘要: poj2406题目大意:给出一个字符串,求出是某个字符串的n次方解决:KMP找出字符串的循环节若有字符串ai...a(j+m),若next[len+1]=m(字符串从1开始),意味着从ai ...am 和 aj...a(j+m)相等,假设中间有相交部分(或者相交部分为0)aj....am,若总长度减去相交部分剩余的部分能被总长度整除,又因为从ai ...am 和 aj...aj+m相等,所以除去相交部分剩余的的两段字符串相等,而且必定满足中间相交部分也能被起始字符串整除,依照这样,即可得出最小的循环节#include <iostream>#include <cstdio> 阅读全文
posted @ 2011-09-02 14:54 猿类的进化史 阅读(508) 评论(0) 推荐(0) 编辑
摘要: hdoj2087题目大意:解决:kmp,与poj3461神似,只需做小小的改动即可#include <iostream>#include <cstring>#include <cstdio>using namespace std;char s[1005],t[1005];int next[1005],lens,lent;void getnext(){ int i=1,j=0; next[1]=0; while(i<=lent) { if(j==0 || t[i]==t[j]) { i++; ... 阅读全文
posted @ 2011-09-02 11:44 猿类的进化史 阅读(320) 评论(0) 推荐(0) 编辑
摘要: poj 2752题目大意:前边的串和后边的串相同的字符的个数解决:kmp的next值,代表前边有多少和从开头的字符串相同#include <iostream>#include <cstdio>#include <cstring>using namespace std;char str[400005];int next[400005];int res[400005];int main(){ while(scanf("%s",str+1)!=EOF) { int i=1,j=0,k=0; next[1]=0; int len=strlen(s 阅读全文
posted @ 2011-09-02 07:38 猿类的进化史 阅读(280) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 14 下一页