poj 2681 字符串】的更多相关文章

http://poj.org/problem?id=2681 给你任意长度的字符串,找出两串字符中不相同的字符个数(总数) #include<string> #include<cstring> #include<iostream> #include<cstdio> using namespace std; int main() { int n; scanf("%d\n",&n); string aa,bb; ; ;i<=n;…
题目链接:http://poj.org/problem?id=1200 题意:给定一个字符串,字符串只有NC个不同的字符,问这个字符串所有长度为N的子串有多少个不相同. 思路:字符串HASH,因为只有NC个不同的字符,所以我们可以把字符串看成是一个NC进制的串,然后计算出字符串的前缀HASH.然后枚举起点判断子串的HASH值是否已经存在.因为有了前缀HASH值,所以转移是O(1)的. #define _CRT_SECURE_NO_DEPRECATE #include<iostream> #in…
http://poj.org/problem?id=3461 先来一发KMP算法: #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <iostream> #include <cmath> #include <map> #include <queue> using namespace std;…
http://poj.org/problem?id=2503 题意:就是翻译,给你一个字典,然后再查找单词,找得到的就输出单词,找不到的输出eh,用Map水题一个,但这个题有点意思的就是输入的问题 #include <iostream> #include <map> #include <string> #include <cstdio> using namespace std; int main() { // freopen("in.txt&quo…
字符串替换 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10871   Accepted: 5100 Description 编写一个C程序实现将字符串中的所有"you"替换成"we" Input 输入包含多行数据 每行数据是一个字符串,长度不超过1000 数据以EOF结束 Output 对于输入的每一行,输出替换后的字符串 Sample Input you are what you do…
题目链接:http://poj.org/problem?id=2503 代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; ; ; int head[HASH],next[maxn]; ],s2[maxn][]; int n; int hash(char *s) { ; ; while(*s) { ret = re…
题意:给出不同字符个数和子串长度,判断有多少个不同的子串 思路:字符串hash. 用字符串函数+map为什么会超时呢?? 代码: #include <iostream> #include <cstring> #include <stdio.h> using namespace std; const int N=16000005; //题目给出子串的最大和不超过16M const int NUM=257; bool hash[N]; int m[NUM]; char st…
Long Long Message #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <queue> #include <stack> #include <cmath> #include <map> #include <string&…
题意: 找出这些串中最长的公共子串(长度≥3),如果长度相同输出字典序最小的那个. 分析: 用库函数strstr直接查找就好了,用KMP反而是杀鸡用牛刀. #include <cstdio> #include <cstring> ][], sub[]; ], l; int cmp(int p1, int p2) { ; i < l; ++i) ][p1 + l] > a[][p2 + l]) return p2; return p1; } int main(void)…
#include<iostream> #include<stdio.h> #include<string> #include<algorithm> #define MAXN 50 using namespace std; char ch1[MAXN]; char ch2[MAXN]; int dig1[MAXN]; int dig2[MAXN]; int main() { //freopen("acm.acm","r"…
#include<iostream> #include<cstring> using namespace std; int main() { string r; int n,dianwei; ; ]; while(cin>>r>>n) { ; ;i<R_LEN;++i) jieguo[i]=result[i]=;//初始化为0 ;i<;++i) chengshu[i]=; dianwei = ; size_t pos = r.find("…
  Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48387   Accepted: 19261 Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A qu…
题目大意: 给定一个数组,求一个最大的长度的子串至少出现过k次 一个子串出现多次,也就是说必然存在2个子串间的前缀长度为所求的值 通过二分答案,通过线性扫一遍,去判断出现次数,也就是说每次遇见一个height[i] , 出现次数就加1,否则重置为1 #include <cstdio> #include <cstring> #include <iostream> using namespace std; ; int rank[N] , sa[N] , height[N];…
Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25426   Accepted: 9300 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given word…
思路: 1. 先把那m个排个序 此后每回二分+strncmp一下就好了 strncmp是个好东西啊-- 2. hash判判 (注意 hash会有冲突--------.) //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,m,ans; struct Node{char a[66];}node[10005],jy; bool…
http://poj.org/problem?id=1917 poj的字符串的一道水题. 题意么无关紧要, 反正输出的第一行就是把那个<>去掉,s1<s2>s3<s4>s5, 也就是第一行就是输出s1s2s3s4s5就行. 第二行就是输出s1s4s3s2s5就可以. #include <stdio.h> #include <string.h> ][]; int main() { ]; char x; scanf("%d%c",…
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(poj3295) (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996) 二.图算法:…
求最长公共子序列LCS,用动态规划求解. UVa的字符串可能含有空格,开始用scanf("%s", s);就WA了一次...那就用gets吧,怪不得要一行放一个字符串呢. (本来想用fgets的,可是又放弃了,形式麻烦.代码长是一小方面,另一方面fgets把'\n'字符也读入,还要做额外的处理...虽然gets有传说中的缓冲区溢出漏洞,不过多加注意一下就好啦,个人认为代码还没大到要用那些工程性的东西的时候) #include <cstdio> #include <cs…
1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood Species POJ 2418D - StationE - Web Navigation ZOJ 1061F - Argus ZOJ 2212G - Plug-in2.SegmentTreeA-敌兵布阵 hdu 1166B - I Hate It HDU 1754C - A Simple Pro…
这个题让求至少出现K次的最大长度的子串,属于最大化最小值问题,首先应该想到二分求字串的长度,二分的过程是O(logN)的,注意judge的时候怎样判断是否满足情况以及满足情况后l,r的变化.可以给每一个子串定一个hash值,判断所有hash值中相同的是否超过K个,hash方法同BDKshash..POJ数据略水..a[i]的值远远没有到100W..poj的字符串题一直感觉数据都不太好..红着脸水过.. #include<cstdio> #include<algorithm> #in…
第一次用到是在‘校内赛总结’扫地那道题里面,大同小异 map<string,int>str 可以专用做做字符串的匹配之类的处理 string donser; str [donser]++ 自动存donser到map并且值加一,如果发现重复元素不新建直接加一, map第一个参数是key,默认字典序升序排列key map<string,int>::iterator ii;         map的迭代器 for(ii=outputer.begin();ii!=outputer.end(…
Numbers That Count Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20396   Accepted: 6817 Description "Kronecker's Knumbers" is a little company that manufactures plastic digits for use in signs (theater marquees, gas station price…
Long Long Message Problem's Link:http://poj.org/problem?id=2774 Mean: 求两个字符串的最长公共子串的长度. analyse: 前面在学习后缀数组的时候已经做过一遍了,但是现在主攻字符串hash,再用字符串hash写一遍. 这题的思路是这样的: 1)取较短的串的长度作为high,然后二分答案(每次判断长度为mid=(low+high)>>1是否存在,如果存在就增加下界:不存在就缩小上界): 2)主要是对答案的判断(judge函数…
编程题#4: 字符串操作 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 给定n个字符串(从1开始编号),每个字符串中的字符位置从0开始编号,长度为1-500,现有如下若干操作: copy N X L:取出第N个字符串第X个字符开始的长度为L的字符串. add S1 S2:判断S1,S2是否为0-99999之间的整数,若是则将其转化为整数做加法,若不是,则作字符串加法,返回…
编程题#2:字符串中次数第2多的字母 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 输入一串长度不超过500个符号的字符串,输出在串中出现第2多的英语字母(大小写字母认为相同)和次数(如果串中有其它符号,则忽略不考虑).如果有多个字母的次数都是第2多,则按串中字母出现的顺序输出第1个. 例 ab&dcAab&c9defgb 这里,a 和 b都出现3次,c和d都出现2…
POJ 1002 - 487-3279(基础)http://acm.pku.edu.cn/JudgeOnline/problem?id=1002题意:略解法:二叉查找数,map,快排... POJ 1200 - Crazy Search(基础)http://acm.pku.edu.cn/JudgeOnline/problem?id=1200题意:找出不相同的子串数量,字母表大小和子串长度会给定,这题很推荐hash入门者一做解法:hash(建议karp-rabin) POJ 1204 - Word…
[题意] 给一个字符串组成的矩阵,规模为n*m(n<=10000,m<=10),如果某两列中存在两行完全相同,则输出NO和两行行号和两列列号,否则输出YES [题解] 因为m很小,所以对每一行枚举其中两个字符串,检查之前行中对应的两列里是否重复即可.但是如何判重. 一开始想的把字符串做成pair然后用map映射为行号,但是TLE. 后来想到用hash判重,可能是因为哈希函数不够好,还是TLE... 总之这道题卡了三个小时,一直TLE. 枚举每一列,对枚举到的那一列从小到大排序,然后找到相邻两个…
题目链接:http://poj.org/problem?id=2406 题意:确定字符串最多是多少个相同的字串重复连接而成的 思路:关键是找到字符串的最小循环节 code: #include <cstdio> #include <cstring> ; char s[MAXN]; int next[MAXN]; void GetNext() { int len = strlen(s); ; ; next[] = -; while (i < len) { == j || s[i]…
在掌握POJ 2774(两个串求最长公共子串)以及对Height数组分组后,本题还是容易想出思路的. 首先用字符集外的不同字符连接所有串,这是为了防止两个后缀在比较时超过某个字符串的分界.二分子串的长度,扫描height数组,判定是否有某个分组来源与至少K个原字符串(本题要求出现超过n的一半次). #include <iostream> #include <vector> #include <algorithm> #include <string> #inc…
题目链接:http://poj.org/problem?id=3974 Time Limit: 15000MS Memory Limit: 65536K Description Andy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, "Can you propose an efficient…