HDU 6153 A Secret】的更多相关文章

A Secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others) Total Submission(s): 2523    Accepted Submission(s): 934 Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,w…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6153 题意:给了串s和t,要求每个t的后缀在在s中的出现次数,然后每个次数乘上对应长度求和. 解法:关键在于想到把s和t都翻转之后,把t求next,然后用t去匹配s,在匹配过程中把fail指针跳到的地方加1,但是还没完,最后需要反向遍历第二个串将大串对小串的贡献加上去就可以了. 这道题是很多现场AC的代码是有漏洞的,比如bazbaba,bazbaba这个答案是34,但是很多现场AC的代码会输出31.…
http://acm.hdu.edu.cn/showproblem.php?pid=6153 首先相当于翻转两个串,然后求s2前缀在s1中出现的次数. 这是一个套路啦 首先把两个串结合起来,中间加一个'%'之类的分割 设dp[i]表示前缀1---i在本串中的出现次数和 那么从后开始dp,所有dp值一开始都是1,表示前缀出现了一次,就是自己本身. 转移,设当前去到第i位,则dp[next[i + 1] - 1] += dp[i] 就是ABACABA这样,已经知道了ABACABA出现了一次,然后前后…
acm.hdu.edu.cn/showproblem.php?pid=6153 [题意] 给定字符串A和B,求B的所有后缀在A中出现次数与其长度的乘积之和 A和B的长度最大为1e6 方法一:扩展kmp [思路] 把A和B同时反转,相当于求B的所有前缀在A中出现次数与其长度的乘积之和 换个角度,相当于A中每出现一个B的前缀,答案中就要加上该前缀的长度 考虑A中每个位置对答案的贡献,A[i...lenA-1]与B的最长公共前缀是x,则B中的前缀B[0...1],B[0....2]...B[0....…
题目链接 Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,which have a big secret.SF is interested in this secret and ask VS how to get it.There are the things that VS tell: Suffix(S2,i) = S2[i...len].Ni is…
A Secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)Total Submission(s): 1530    Accepted Submission(s): 570 Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,wh…
A Secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)Total Submission(s): 817    Accepted Submission(s): 321 Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,whi…
题意:给定两个串,求其中一个串 s 的每个后缀在另一个串 t 中出现的次数. 析:首先先把两个串进行反转,这样后缀就成了前缀.然后求出 s 的失配函数,然后在 t 上跑一遍,如果发现不匹配了或者是已经完全匹配了,要计算,前面出现了多少个串的长度匹配也就是 1 + 2 + 3 + .... + j 在 j 处失配,然后再进行失配处理.注意别忘了,匹配完还要再加上最后的. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000"…
题意 : 给出两个字符串,现在需要求一个和sum,考虑第二个字符串的所有后缀,每个后缀对于这个sum的贡献是这个后缀在第一个字符串出现的次数*后缀的长度,最后输出的答案应当是 sum % 1e9+7 分析 : 有两种做法,如果会拓展KMP的话可以说这就是一道模板题了,拓展KMP专门就是找最长公共前缀的长度,首先将给出的两个字符串双双反转,用模式串去跟主串跑一遍拓展KMP,得到 extend 数组,然后只要遍历一遍 extend 数组,每一个 extend[i] 表示模式串里面前 extend[i…
Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,which have a big secret.SF is interested in this secret and ask VS how to get it.There are the things that VS tell: Suffix(S2,i) = S2[i...len].Ni is the…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6153 扩展kmp不理解的看下:http://www.cnblogs.com/z1141000271/p/7404717.html 大致题意:给定一个a串作为 母串,然后b作为模式串, f[i] 为b的后缀的长度. d[i] 为b这个后缀在 a串中出现的次数.. 问你他们的 积是多少,积mod1e9+7 题解:赛后补题目的时候,看到大佬用扩展kmp解,就去看了下扩展kmp,然后把第一个输入的字符串当t…
A Secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)Total Submission(s): 975    Accepted Submission(s): 372 Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,whi…
A Secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)Total Submission(s): 1666    Accepted Submission(s): 614 Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,wh…
最终刷KMP目标就是为了挑战这道题!现在成功了恩... 首先,题目大意是:给出一个字符串str1,之后给出另一个字符串str2,问,str2的后缀在str1匹配的次数*后缀当前长度是多少 首先考虑正统求前缀的KMP 要求的是有限状态自动机不停地“返回前面的值”从而进行匹配,而这道题要求自动机向后返回,直觉告诉我应该考虑反转这个字符串的可能 对于设计样例: A B C D A B C 来说,首先考虑匹配的具体状况:ABC*3,BC*2,C*1.其中C出现三次 考虑倒置情况,D C B A,和C B…
Secret Code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 670    Accepted Submission(s): 109 Problem Description The Sarcophagus itself is locked by a secret numerical code. When somebody wan…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4082 题目大意: 给你n个点,问能最多构成多少个相似三角形. 用余弦定理,计算三个角度,然后暴力数有多少个,更新答案. 代码: #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <vector> #include <set>…
http://acm.hdu.edu.cn/showproblem.php?pid=1111 复数除法: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ]; __int64 n; int x1,y1,b1,b2; int t1; bool flag; void dfs(int cnt) { ) return; &&y1==) { flag=tr…
http://acm.hdu.edu.cn/showproblem.php?pid=2113 Problem Description 有一天, KIKI 收到一张奇怪的信, 信上要KIKI 计算出给定数各个位上数字为偶数的和.eg. 5548结果为12 , 等于 4 + 8 KIKI 很苦恼. 想请你帮忙解决这个问题.   Input 输入数据有多组,每组占一行,只有一个数字,保证数字在INT范围内.   Output 对于每组输入数据,输出一行,每两组数据之间有一个空行.   Sample I…
Secret Code Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description The Sarcophagus itself is locked by a secret numerical code. When somebody wants to open it, he must know the code and set it exactly o…
Hou Yi's secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1881    Accepted Submission(s): 450 Problem Description Long long ago, in the time of Chinese emperor Yao, ten suns rose into the…
题意: 给n个点,问最多有多少个相似三角形(三个角对应相等). 解法: O(n^3)枚举点,形成三角形,然后记录三个角,最后按三个角度依次排个序,算一下最多有多少个连续相等的三元组就可以了. 注意:在同一个坐标的两点只算一次,所以要判一下. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #includ…
Problem Description 有一天, KIKI 收到一张奇怪的信, 信上要KIKI 计算出给定数各个位上数字为偶数的和. eg. 5548 结果为12 , 等于 4 + 8 KIKI 很苦恼. 想请你帮忙解决这个问题. Input 输入数据有多组,每组占一行,只有一个数字,保证数字在INT范围内. Output 对于每组输入数据,输出一行,每两组数据之间有一个空行. Sample Input 415326 3262 Sample Output 12 10 简单题. 注意输出格式就行!…
直接6重循环就行了吧...判三角形相似直接从小到大枚举两向量夹角是否相等就行了.注意去重点跟三点共线就行了... #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<fstream> #include<sstream> #include<bitset> #include<vector> #incl…
题目链接 题意 : 给你复数X的Xr和Xi,B的Br和Bi,让你求一个数列,使得X = a0 + a1B + a2B2 + ...+ anBn,X=Xr+i*Xi,B=Br+Bi*i : 思路 : 首先要知道复数的基本运算,题目中说0 <= ai < |B| ,|B|代表的是复数的模,|B|=√(Br*Br+Bi*Bi).将题目中给定的式子X = a0 + a1B + a2B2 + ...+ anBn,进行变型得:X=a0 + (a1 + (a2 + ...(an-1+ an*B))) .所以…
题意:射箭落在n个点,任取三点可构成一个三角形,问最大的相似三角形集(一组互相相似的三角形)的个数. 分析: 1.若n个点中有相同的点,要去重,题目中说射箭会形成洞,任选三个洞构成三角形,因此射在同一点只形成一个洞. 2.二进制枚举子集选出三个点,判断能否构成三角形. 3.因为边长可能为小数,因此用边长的平方判断相似. (1)将比较的两个三角形三边分别排序 (2)tmpx[0] / tmpy[0] = tmpx[1] / tmpy[1] = tmpx[2] / tmpy[2],即若满足tmpx[…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Description Problem Description A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the b…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5446 Unknown Treasure 问题描述 On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown to the map. The mathematician entered the cave because it is there. Somewhere…
http://acm.hdu.edu.cn/showproblem.php?pid=4815 Description A crowd of little animals is visiting a mysterious laboratory � The Deep Lab of SYSU. “Are you surprised by the STS (speech to speech) technology of Microsoft Research and the cat face recogn…
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i…
Secret Code 问题描述 The Sarcophagus itself is locked by a secret numerical code. When somebody wants to open it, he must know the code and set it exactly on the top of the Sarcophagus. A very intricate mechanism then opens the cover. If an incorrect cod…