自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

yzl_rex

对于算法,我只是一个草民!

  • 博客(435)
  • 资源 (4)
  • 收藏
  • 关注

原创 poj 1840 Eqs

//下面的做法为直接链址法 #include #include using namespace std;const int MAX = 18750001;//这个数的由来,由其系数最大值决定:50^4 = 18750000; short hash[MAX*2 + 10];int main(){ short a1, a2, a3, a4, a5, x1, x2, x3, x

2012-08-16 10:05:40 505

原创 哈希表的详解

哈希表(Hash table,也叫散列表),是根据关键码值(Key value)而直接进行访问的数据结构。也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度。这个映射函数叫做散列函数,存放记录的数组叫做散列表。哈希表的做法其实很简单,就是把Key通过一个固定的算法函数既所谓的哈希函数转换成一个整型数字,然后就将该数字对数组长度进行取余,取余结果就当作数组的下标,将va

2012-08-16 10:03:06 7863

原创 poj 1604 Just the Facts

//通过打表就OK,求阶乘的末尾不为0的第一位数字! #include #include #include using namespace std;int ans[10010];void solve(){ int i, mult; memset(ans, 0, sizeof(ans)); ans[1] = 1; mult = 1;

2012-08-15 10:58:15 862

转载 poj 1423 Big Number

题意:给出一个数字N,求N!的结果的位数。首先要求一个数字有多少位,可以用(int)log10(num)+1,这样就求出num有多少位.数N可以到10^7这么大,直接暴力的话 肯定超时。考虑下面两种方法,个人比较推荐第二种。第一种是直接打表,避免重复计算,如果要追求速度的话,可以在程序外打表,然后导入,在程序中直接查,即可,那样肯定0MS,下面的代码是在程序中打表的,所以时间爱你耗

2012-08-15 09:48:35 1751

转载 动态规划解最长公共子序列问题

动态规划法经常会遇到复杂问题不能简单地分解成几个子问题,而会分解出一系列的子问题。简单地采用把大问题分解成子问题,并综合子问题的解导出大问题的解的方法,问题求解耗时会按问题规模呈幂级数增加。为了节约重复求相同子问题的时间,引入一个数组,不管它们是否对最终解有用,把所有子问题的解存于该数组中,这就是动态规划法所采用的基本方法。【问题】 求两字符序列的最长公共字符子序列

2012-08-14 16:57:58 619

原创 poj 1458 Common Subsequence

//第一道LCS,最开始我以为是简单的遍历字符串就可以,但是提交上去WA了,再看讨论,才知道用LCS的,//然后就上网找关于LCS的资料,在似懂非懂的情况之下敲了出来!还需要这方面的练习! #include #include #include using namespace std;const int MAXLEN = 1000;int ans[MAXLEN][MAXLEN];

2012-08-14 16:55:56 378

原创 poj 1663 Number Steps

#include using namespace std;int main(){ int tc, i, x, y; cin >> tc; bool flag; while (tc--){ cin >> x >> y; flag = false; if (x % 2 == 0 && y % 2

2012-08-10 21:38:58 601

原创 poj 1674 Sorting by Swapping

#include #include #include using namespace std;int num[10010];int main(){ int tc, n, i, j, ans; cin >> tc; while (tc--){ cin >> n; ans = 0; memset(num

2012-08-10 20:13:54 991

原创 poj 3749 破译密码

#include #include #include #include using namespace std;map m;int main(){ int i, len; string str, ans; ans.clear(); m['A'] = 'V', m['B'] = 'W', m['C'] = 'X', m['D'] = 'Y', m['

2012-08-09 10:34:03 763

原创 poj 3297 Open Source

//这题由于用了set中的erase总是出现段错误,所以不得不要转换过来,用了比较繁琐的转换!代码亦加长了不少!囧! #include #include #include #include #include using namespace std;set::iterator it;struct Info{ string project; se

2012-08-09 10:12:57 783

原创 erase方法的正确使用

STL中的容器按存储方式分为两类,一类是按以数组形式存储的容器(如:vector 、deque);另一类是以不连续的节点形式存储的容器(如:list、set、map)。当运用到STL中的函数的时候,在使用erase方法来删除元素时,需要注意一些问题(本人还没有彻底的理解到其出现问题的原因,等我学会了其容器的储存形式之后,再回过头来解释其原因,以下的内容仅是阅读笔记)。当你想遍历删除一个容器

2012-08-09 10:04:08 3468

原创 poj 2803 Defining Moment

//其实是一道很水的题,点知道我在没有读懂题意的情况之下,把其做法往深处想了!//注意:You need to expand at most one prefix and one suffix,意思是说只要进行一次前缀和后缀的//转换即可(要在有前缀和后缀的情况之下啊) #include #include #include using namespace std;string p

2012-08-08 08:53:04 554

原创 poj 2643 Election

//这题要注意的两点是:1.注意要用cin.get()输入其结束标志,要不对getline()的输入造成影响//2.要注意选举人的票数相同的情况,例如:最高票数的有两个选举人,那么结果就是tie了! #include #include #include using namespace std;struct Info{ string name, party;

2012-08-07 19:47:02 628

原创 poj 2629 Common permutation

//虽然是水题一题,但是陷阱多多,要多加小心!//1.输入的两个字符串中可能存在着空格!//2.当输入有空行的时候,输出的答案是空行! #include #include #include using namespace std;int main(){ int i, j, lena, lenb; string a, b, ans; while (getl

2012-08-07 16:28:16 881

原创 poj 2403 Hay Points

#include #include #include using namespace std;map mymap;int main(){ int i, m, n, point, ans; string str, word; cin >> m >> n; for (i = 0; i < m; i++){ cin >> str >> po

2012-08-07 15:44:17 833

原创 c++中string类的详解

通过在网站上的资料搜集,得到了很多关于string类用法的文档,通过对这些资料的整理和加入一些自己的代码,就得出了一份比较完整的关于string类函数有哪些和怎样用的文档了!下面先罗列出string类的函数有哪一些,然后再罗列出函数的原型,最后到代码的实现标准C++中提供的string类得功能也是非常强大的,一般都能满足我们开发项目时使用。现将具体用法的一部分罗列如下,只起一个抛砖

2012-08-07 15:24:12 110780 18

原创 poj 1583 Choose Your Words Carefully

//这题足足用了我4个多小时来检查错误(半个小时写代码)!实在太愚蠢了!头都爆了!哎!//而且这一题并没有区分大小写的,一般没有考虑到的情况,都可以通过代码后面的样例发现,//这题实在太坑爹了!被折磨了数小时,经历了无限次WA!虽然是水题一道! #include #include #include using namespace std;map m;map::iterator i

2012-08-06 22:41:24 1016

原创 poj 1598 Excuses, Excuses!

//这题有两点需要注意的:1.有可能excuses中存在着大写字母,这就需要将其大写字母转换为小写字母再比较//2.keysword不能是excuses中的字串,而是一个单词,具体见下面的样例! #include #include #include #include using namespace std;struct Info{ int c; str

2012-08-06 19:05:30 625

原创 poj 1590 Palindromes

//这题需要考虑的情况也比较多,有点烦,一定需要用清晰的思路,要不很容易出错,尤其是对四种情况的讨论! //这题WA了两次,一次是:输出的英文写错了,是自己手打的,没有进行对样例的复制粘贴,下次要谨记!//第二次是没有讲‘O’和‘0’考虑进去,粗心了! #include #include using namespace std;int main(){ int i, j,

2012-08-06 14:03:04 494

原创 poj 1572 Automatic Editing

#include #include #include #include using namespace std; struct Info{ int rule; string str1, str2; map mymap;};//字符串的替换!用库函数的replace会出错,第一次还可以,当用到第二次的时候就出错!我也不知道错在哪!//找

2012-08-06 12:16:00 513

原创 poj 1617 Crypto Columns

//这题总的来说是水题,只要认真的理解到题目的意思就很容易了! #include #include #include using namespace std;int main(){ int i, j, len1, len2; string keyword, ciphertext, ans, tmp1, tmp2, order, div[100]; while

2012-08-05 12:33:48 523

原创 poj 2001 Shortest Prefixes

//字典树的入门题,感觉还可以,就是当我用cin输入的时候,我一直在考虑紧,怎样结束输入的,在网上也找了//很多的解题报告,发觉他们都是用scanf()!= EOF来解决的!而后来再找,原来cin是直接就包含了这一个条件了,//所以它会自动判断是否输入结束的,提交上去,顺利AC了,如果你想看结果的,就要设置一定条件,使其输入结束! //直接套用字典树的模板就可以解决问题! #include

2012-08-04 16:42:07 365

原创 poj 3630 Phone List

//竟然用sort排序之后的做法比trie还要快!应该我对trie的掌握还不够熟练吧! #include #include #include using namespace std;int main(){ int tc, i, n; string str[10010]; bool flag; cin >> tc; while (tc--){

2012-08-04 10:42:12 1043 1

原创 poj 1056 IMMEDIATE DECODABILITY

//这一题用暴力求解可以过,但是当数据比较大的时候,就肯定会超时,所以就用到了字典树,这也是我第一次接触字典树,花了几小时//看懂了字典树的原理之后,再看懂别人的代码,自己打出来,无办法,第一次接触,还需要多多的练习! /*#include #include #include using namespace std;vector v; int main(){ int

2012-08-04 08:17:58 654

原创 poj 3366 Deli Deli

#include #include #include using namespace std;map m; map::iterator it; int main(){ int l, n, i, len; string str1, str2; bool flag; cin >> l >> n; for (i = 0; i < l; i

2012-07-29 12:11:26 979

原创 poj 1917 Automatic Poetry

//主要就是考察输入输出的题目,竟然用了那么久来解决这个问题!自己的基础还不行! #include #include #include using namespace std;int main(){ int tc, len1, len2, i, j, pos1, pos2, pos3, pos4; string input1, input2, s1, s2, s3,

2012-07-29 10:51:07 635

原创 strcpy strlen memcpy strcat strcmp strstr strrev函数的实现代码

/* //strcpy函数的实现,注意命名要与原来的库函数有区别 #include #include #include using namespace std;char *mystrcpy(char *strDest, const char *strSrc){ if ((strDest == NULL) || (strSrc == NULL))//保证strDest和st

2012-07-24 10:53:01 1389

原创 线性表的链式存储结构的实现

#include #include #include using namespace std;typedef int ElemType;typedef struct LNode{ ElemType data; struct LNode *next;}LinkList;LinkList *p, *q, *L;//链表的初始化,创建一个带头结点的

2012-07-22 17:19:22 4147

原创 KMP算法

//KMP算法的难度就在于next数组的求解和这个next数组与要匹配的主模式串有什么联系,搞明白了这个联系,//再理解KMP算法就没有想象中的那么难了!网上的资料也有很多关于KMP算法的剖析,总的可以归纳为一句话:构造最大后缀长度数组!//学什么都不可能一蹴而就的,需要经验的积累,时间的洗礼! #include #include using namespace std;int ne

2012-07-22 13:15:13 517

原创 poj 1035 Spell checker

//需要考虑的情况比较多,要一步一步地进行模拟,要小心其值是取哪一个字符串的长度! #include #include #include #include using namespace std;vector v;void is_replace(string str1, string str2) { int i, len, c = 0; len = str1.

2012-07-21 01:04:01 386

原创 poj 3752 字母旋转游戏

//和蛇形填数是同一种类型的题目,要进行预判断! #include using namespace std;char map[10000][10000];int main(){ int i, j, m, n, tot; char ch = 'A'; cin >> m >> n; for(i = 0; i < m; i++) fo

2012-07-20 12:50:23 918

原创 poj 3751 时间日期格式转换

//对c语言中的输入和输出熟悉的情况之下就很快可以解决问题了! #include #include #include using namespace std;int main(){ int tc, year, day, month, hour, min, sec; scanf("%d", &tc); while (tc--){ scanf

2012-07-20 09:05:20 819 2

原创 poj 1488 TEX Quotes

//这题主要是两种左右引号比较难分清楚,只要将样例的copy下来,再通过键盘的尝试就容易得出! #include #include using namespace std;int main(){ int len, i; string str; bool flag = true; while (getline(cin, str)){

2012-07-19 20:48:57 850

原创 线性表的顺序存储结构的实现

1.初始化线性表L,即进行动态存储空间分配并置L为一个空表2.清除线性表L中的所有元素,释放存储空间,使之成为一个空表3.返回线性表L当前的长度,若L为空则返回0 4.判断线性表L是否为空,若为空则返回1, 否则返回0 5.返回线性表L中第pos个元素的值,若pos超出范围,则停止程序运行6.顺序扫描(即遍历)输出线性表L中的每个元素 7.从线性表L中查找值与x相等的元素,若查找成功则

2012-07-19 20:07:09 6091

原创 poj 2406 Power Strings

//题目大意:a是一个字符串,记s=a^n为a重复n次所形成的字符串。//比如说a是abcd,那么当n=3时,a^3就是abcdabcdabcd。现在给出字符串s,求出最大的n #include #include #include #include using namespace std;int next[100000001];void get_next(string str,

2012-07-18 10:07:23 606

原创 poj 1961 Period

//这题如果理解了KMP算法中next数组的具体代表什么和求解过程,问题就不大了! #include #include #include using namespace std;int next[1000010];//next数组的求解! void get_next(string str, int *next, int len){ int i, j; next

2012-07-18 09:29:08 685

原创 四则运算表达式求值(栈的应用)

1.前/中/后缀表达式的转换(首先需要明白三者之间的转换)      自然表达式转换为前/中/后缀表达式,其实是很简单的。首先将自然表达式按照优先级顺序,构造出与表达式相对应的二叉树,然后对二叉树进行前/中/后缀遍历,即得到前/中/后缀表达式。    举例说明将自然表达式转换成二叉树:    a×(b+c)-d    ① 根据表达式的优先级顺序,首先计算(b+c),形成

2012-07-14 10:22:53 30645 9

原创 poj 2390 Bank Interest

#includeusing namespace std;int main(){ double r, m, y, ans; int i; cin >> r >> m >> y; ans = 0; r = r * 1.0 / 100 + 1; for (i = 0; i < y; i++){ ans = m * r;

2012-07-11 01:18:07 692

原创 poj 2363 Blocks

//暴力0ms通过,题目的意思是:包装这些立方体所需要的包装纸的最小表面积! #include#includeusing namespace std;int main(){ int tc, cube, i, a, b, c, min, tmp; cin >> tc; while (tc--){ cin >> cube; m

2012-07-11 01:06:56 691

原创 poj 2350 Above Average

//主要考察浮点数的处理! #include#includeusing namespace std;int scores[1010];int main(){ int tc, num, i, c; double sum, average, ans; cin >> tc; while (tc--){ cin >> num;

2012-07-10 11:03:04 481

masm.exe link.exe

是汇编语言中需要用到的编译文件masm.exe 和链接文件link.exe

2011-12-08

麻省理工大学的算法导论(英文版)

该书为麻省理工大学的“算法导论”,为英文版,希望可以带给你们方便!

2011-08-21

数据结构算法与应用-C++语言描述

这是一本用c++语言来描述关于数据结构算法与应用的基础书籍,对于刚刚接触算法的人来说,打好基础最重要!

2011-08-19

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除