随笔分类 -  POJ

POJ 2406 Power Strings (KMP)
摘要:题目地址:http://poj.org/problem?id=2406对于这道题,考的就是KMP算法中对于子串的自匹配模式的考察。具体的KMP算法可参看KMP算法详解,主要看对B串的处理。这题给出一个比较特殊的测试数据供大家参考aabaaaba结果应该为2 1 #include <stdio.h> 2 #include <string.h> 3 4 void result(char str[1000001]) 5 { 6 int i; 7 int j; 8 int len = strlen(str); 9 int p[1000001];10 p[0] = -1;11 . 阅读全文

posted @ 2012-10-08 12:10 NULL00 阅读(558) 评论(0) 推荐(0)

POJ 2479 Maximum sum (动态规划)
摘要:POJ 2479 Maximum sum,题目大意是:对于给定的整数序列A={a1, a2,..., an},我们如下定义函数 d(A):我们的目标就是求出d(A)解决方案:这个题目是一个典型的动态规划题目,我们可以这样看,d(A)最大,即两个子序列之和最大,而这两个子序列是不相交的,因而我们可以将题目转换为如下形式:第一步,对于位置i,求i左边序列(可以包含i)的最大值和i右边序列的最大值。在程序中分别用leftMax和rightMax数组进行保存。第二步,然后对i取不同的值,即遍历i,得到d(A)。如对于序列A = {1 -1 2 2 3 -3 4 -4 5 -5},我们对于A[0],求其 阅读全文

posted @ 2012-07-02 15:04 NULL00 阅读(2431) 评论(0) 推荐(0)

POJ 2418 Hardwood Species
摘要:题目地址为http://poj.org/problem?id=2418这题,我起先用的是AVL树,结果时间超时,最后发现,直接用二叉树就行了,根本就不需要旋转。由于数据是随机的,因而这棵二叉树的性能还行。当然还可以用trie树来解决。题目很简单,直接上代码 1 #include <iostream> 2 #include <stack> 3 #include <string.h> 4 #include <stdio.h> 5 #include <stdlib.h> 6 using namespace std; 7 8 class No 阅读全文

posted @ 2012-06-29 13:28 NULL00 阅读(698) 评论(0) 推荐(0)

POJ 1423 Big Number
摘要:Big NumberDescriptionIn many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number.InputInput 阅读全文

posted @ 2012-06-28 14:54 NULL00 阅读(1179) 评论(1) 推荐(1)

POJ 1458 Common Subsequence (最长公共子序列)
摘要:Common SubsequenceDescriptionA subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = < x1, x2, ..., xm > another sequence Z = < z1, z2, ..., zk > is a subsequence of X if there exists a strictly increasing sequence < i1 阅读全文

posted @ 2012-06-26 13:50 NULL00 阅读(1633) 评论(0) 推荐(1)

POJ 1019 Number Sequence
摘要:Number SequenceDescriptionA single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a sequence of positive integer numbers ranging from 1 to k, written one after another.For example, the fir 阅读全文

posted @ 2012-06-25 14:27 NULL00 阅读(1679) 评论(0) 推荐(0)

POJ 3984 迷宫问题 (Dijkstra)
摘要:迷宫问题Description定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0,};它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。Input一个5 × 5的二维数组,表示一个迷宫。数据保证有唯一解。Output左上角到右下角的最短路径,格式如样例所示。Sample Input0 1 0 0 00 1 0 1 00 0 0 0 00 1 1 1 00 0 阅读全文

posted @ 2012-06-22 13:57 NULL00 阅读(6600) 评论(1) 推荐(1)

POJ 1753 Flip Game (递归枚举)
摘要:POJ 1753,题目链接http://poj.org/problem?id=1753,翻译一下整个题目的大概意思:有4*4的正方形,每个格子要么是黑色,要么是白色,当把一个格子的颜色改变(黑->白或者白->黑)时,其周围上下左右(如果存在的话)的格子的颜色也被反转,问至少反转几个格子可以使4*4的正方形变为纯白或者纯黑?主要思路如下:1.对于每个格子,它要么反转0次,要么反转1次(当然,它的邻格子也跟着反转),因为它反转偶数次和反转0次的效果是一样的,同理反转奇数次的效果和反转1次的效果是一样的。2.由于只有16个格子,我们可以选择0个格子,1个格子,2个格子,3个格子..... 阅读全文

posted @ 2012-04-27 19:44 NULL00 阅读(24456) 评论(2) 推荐(1)

POJ 1177 Picture (线段树+离散化+扫描线) 详解
摘要:POJ 1177 (线段树+离散化+扫描线),题目链接为http://poj.org/problem?id=1177在做本题之前,必须先了解什么是线段树和离散化,请看前一篇博文线段树(segment tree),里面对线段树和离散化的说明相对比较清楚了。对于这题,我们的思路步骤如下(代码和下面的文字解释结合着看):1.对于输入的N个矩形,有2*N条纵向边,我们把这些边叫做扫描线2.建立一个struct ScanLine,保留这些扫描线struct ScanLine{ int x;//横坐标 int y1;//扫描线的下端点 int y2;//扫描线的上端点 int flag;//若该扫... 阅读全文

posted @ 2012-04-22 12:49 NULL00 阅读(7523) 评论(5) 推荐(5)

POJ 1001 Exponentiation
摘要:DescriptionProblems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems. This problem requires that you write a program to compute the exact value of Rn where R 阅读全文

posted @ 2012-04-13 16:29 NULL00 阅读(1417) 评论(0) 推荐(0)

导航