poj 3729 Facer’s string】的更多相关文章

Facer’s string Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 2155   Accepted: 644 Description Minifacer was very happy these days because he has learned the algorithm of KMP recently. Yet his elder brother, Hugefacer, thought that Mini…
                                                                                                  Facer’s string Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 1783   Accepted: 537 Description Minifacer was very happy these days because…
Description Facer is addicted to a game called "Tidy is learning to swim". But he finds it too easy. So he develops a new game called "Facer is learning to swim" which is more difficult and more interesting. In the new game, a robot na…
http://poj.org/problem?id=2887 题意:给出一个字符串,还有n个询问,第一种询问是给出一个位置p和字符c,要在位置p的前面插入c(如果p超过字符串长度,自动插在最后),第二种询问是给出一个位置p,查找第p个位置的字符(p保证合法). 思路:暴力分块.一开始建成块之后,每次插入就在每个块的字符串插入字符,因为询问最多只有2000个,所以就算极端情况也不会超时. 注意:sz和cnt其中一个要向上取整.用string类会超时. #include <cstring> #in…
参考连接: KMP+DP: http://www.cnblogs.com/yuelingzhi/archive/2011/08/03/2126346.html 另外给出一个没用dp做的:http://blog.sina.com.cn/s/blog_82061db90100usxw.html 题意: 给出一个字符串,求它的各个前缀在字符串中出现的次数总和. 思路:记 dp[i] 为前 i 个字符组成的前缀出现的次数则 dp[next[i]]+=dp[i] dp[i]表示长度为i的前缀出现的次数,初…
Given a string… Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 1819   Accepted: 390 Case Time Limit: 2000MS Description Peter’s Boss is now very upset. He said that Peter’s vision of the orthogonal sum of two strings is not collinear t…
题意 一个$n*n$矩阵,初始全为0,每次翻转一个子矩阵,然后单点查找 题解 任意一种能维护二维平面的数据结构都可以 我这里写的是二维线段树,因为四分树的写法复杂度可能会退化,因此考虑用树套树实现二维线段树 简单来说就是每个点都维护了一颗线段树... 因为二维线段树难以实现pushdown,而他的查找又是单点的 于是具体思路类似标记永久化,记录经过的点上的修改次数,最后判断修改次数的奇偶性即可 //为什么不写构造函数和vector? //因为这是神奇的poj... #include<iostre…
题意: 给你n个串串,每个串串可以选择和n个字符串拼接(可以自己和自己拼接),问有多少个拼接后的字符串是回文. 所有的串串长度不超过2e6: 题解: 这题由于是在POJ上,所以string也用不了,会tle. 串串个数也比较多,开不下二维的char数组,卡内存. 所以数据的预处理需要处理成一个串串,把所有的串串放在一个串里面. 记录每一个串串的起始位置和长度. 数据预处理部分就解决了. 然后就是核心思想部分了. 首先你要知道如何用EX_KMP求串串前缀和后缀是否是回文.(其实也可以用马拉车) 其…
转自 stven_king的博客 这是一个求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm>下面是以前的笔记  (1) int 类型的next_permutation int main(){ int a[3];a[0]=1;a[1]=2;a[2]=3; do {cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;} while…
这是一个求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm>下面是以前的笔记    与之完全相反的函数还有prev_permutation  (1) int 类型的next_permutation int main(){ int a[3];a[0]=1;a[1]=2;a[2]=3; do{cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<…
题目地址 简单的全排列输出,借用stl中的next_permutation就非常简单了. 关于next_permutation:(备忘,来源网络) /*这是一个求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm> 与之完全相反的函数还有prev_permutation*/ //(1) int 类型的next_permutation int main() { ]; a[]=;a[]=;a[]=; do { cout<<a[]<<]<<…
C++中全排列函数next_permutation 用法 转载 2017年03月29日 14:38:25 1560 全排列参考了两位的博客 感谢! http://blog.sina.com.cn/s/blog_9f7ea4390101101u.html http://blog.csdn.net/ac_gibson/article/details/45308645 早就听说了了next_permutation 产生全排列的强大,一直到昨晚遇到一个对字符串产生全排列的问题才知道这个函数的强大,我们队…
学习: http://blog.sina.com.cn/s/blog_9f7ea4390101101u.html http://blog.csdn.net/ac_gibson/article/details/45308645 https://blog.csdn.net/HowardEmily/article/details/68064377 next_permutation(start,end)和 prev_permutation(start,end). 这两个函数作用是一样的,区别就在于: 前…
题目描述(题目链接:https://www.luogu.org/problem/P1091) NN位同学站成一排,音乐老师要请其中的(N-KN−K)位同学出列,使得剩下的KK位同学排成合唱队形. 合唱队形是指这样的一种队形:设K位同学从左到右依次编号为1,2,…,K1,2,…,K,他们的身高分别为T_1,T_2,…,T_KT1​,T2​,…,TK​, 则他们的身高满足T_1<...<T_i>T_{i+1}>…>T_K(1 \le i \le K)T1​<...<T…
next_permutation函数 组合数学中经常用到排列,这里介绍一个计算序列全排列的函数:next_permutation(start,end),和prev_permutation(start,end).这两个函数作用是一样的,区别就在于前者求的是当前排列的下一个排列,后一个求的是当前排列的上一个排列.至于这里的“前一个”和“后一个”,我们可以把它理解为序列的字典序的前后,严格来讲,就是对于当前序列pn,他的下一个序列pn+1满足:不存在另外的序列pm,使pn<pm<pn+1. 对于ne…
map      容器和数组一样,不过比较活用,相当于直接离散化数组 map<int ,int>mp 一维int map<string ,string>mp 一维 str map<int,map<int ,int> >mp 二维,经常大数hash时候用 map<int ,multiset<int> >mp 一对多的关系,相当于一个离散化并且随时可以删除指定元素,获得元素个数的灵活二维容器....    set     是个容器,有集合…
题目大意 给一个字符串,长度不超过 106,有两种操作: 1. 在第 i 个字符的前面添加一个字符 ch 2. 查询第 k 个位置是什么字符 操作的总数不超过 2000 做法分析 好多不同的做法都可以搞 人生第一个块状链表,记录下 块状链表的思想其实挺简单的,传统的链表每个节点只记录一个字符,块状链表的每个节点记录的是 sqrt(n) 个信息,一个长度为 n 的字符串就被分成了 sqrt(n) 个.这样,查询和插入字符的操作就变成了 sqrt(n)级别的了,对于这题 2000 个操作来讲,时间复…
题目连接 http://poj.org/problem?id=2887 Big String Description You are given a string and supposed to do some string manipulations. Input The first line of the input contains the initial string. You can assume that it is non-empty and its length does not…
题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 "S is surprising." , 反之,则输出 "S is NOT surprising." . 例如 AABA 把它分成两个字符为一个整体的,1..相邻两个字符 AA,AB,BA 没有相同的;    2.隔一个字符的 AB AA 没有相同;          3.隔…
题目:http://poj.org/problem?id=2887       Big String Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 6527   Accepted: 1563 Description You are given a string and supposed to do some string manipulations. Input The first line of the input…
标题意味着小神童.加减可以计算. 只是说这个小神童的学科知识,究竟有多神,自己给自己找. 最后,因为数据是非常非常巨大的,我听说关闭50k结束了50000数字总和,可以想见他神教. 这似乎也是考试题目IQ什么! 水题,依照一般加减法做,肯定是WA了. 这里给出使用string的加减法运算.由于string是长度可增可减的,所以无论是多少位,仅仅要内存支持,那么本算法都能够支持了.也能够使用vector这些容器.只是string应该更加省点内存. 注意: POJ比較讨厌的就是不支持C++11,并且…
Big String Time Limit: 1000MS Memory Limit: 131072K Description You are given a string and supposed to do some string manipulations. Input The first line of the input contains the initial string. You can assume that it is non-empty and its length doe…
String Matching Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4074   Accepted: 2077 Description It's easy to tell if two words are identical - just check the letters. But how do you tell if two words are almost identical? And how close…
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14471 Accepted: 6633 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of po…
String reduction Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1360   Accepted: 447 Description There is a string of characters 'a' and 'b' with the length of no more than 255 characters. You can perform the substring reduction on the…
题目大意,给出一个字符串s,求最大的k,使得s能表示成a^k的形式,如 abab 可以表示成(ab)^2: 方法:首先 先求kmp算法求出next数组:如果 len mod (len-next[len])==0 ,答案就是 len /(len-next[len]),否则答案是1:证明如下: 如果s能表示成 a^k的形式且k>1,k尽可能大,即s可以表示成aaaaaa(k个a):那么next[len]就等于k-1个a的长度:aaaaaaa  aaaaaaa那么 (len-next[len])a的长…
题意:给一个字符串(<=1000000)和n个操作(<2000),每个操作可以在某个位置插入一个字符,或者查询该位置的字符.问查询结果. 思路:块状数组. 如果将原来的字符串都存在一起,每次插入肯定会超时. 而操作数比较少,考虑使用分块法.假设原字符串长度为L,则取每块长度l=sqrt(L).这样每次插入,我们需要用sqrt(L)的时间找到对应的块,再用sqrt(L)在该块进行插入.查询同样需要sqrt(L)找到该块,如果用数组实现可以O(1)找到目标元素.(我尝试用stl链表来做,结果超时了…
算出next数组. 对于任何一个循环字串,len-next[len]必为最小循环节长度 若len%(len-next[len])==0 即为循环字串,n=len/(len-next[len]) 否则输出1 代码: #include<cstdio> #include<cstring> using namespace std; ; char str[N]; int next[N],ans,len; void make() { ,j=-; next[i]=j; while(i<le…
题意: 给你一个不超过1e6的字符串,和不超过2000次的操作 操作分为两种: 1.将一个字符插入到某个位置的前面 2.询问当前位置的字符 /* 块状链表模板水题(我的智商也就能做这种题了). 观察题目,我们发现询问次数是很少的,所以可以考虑暴力? 很明显暴力就会gg,但是可以把这n个字母分为√n 块,然后查找的时候先用√n的时间找出在哪一块, 然后只在这一块中找就行了. */ #include<cstdio> #include<iostream> #include<cstr…
Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9613   Accepted: 2296 Description Facer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make th…