CodeForces 113B Petr#】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/113/B 题目大意: 多组数据每组给定3个字符串T,Sbeg,Sed,求字符串T中有多少子串是以Sbeg开头,Sed结尾的 分析: 难点在哈希函数的编写,如果直接存string会爆内存,不能用STL自带哈希函数,用了会Wa. 代码如下: #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i &l…
应该算是远古时期的一道题了吧,不过感觉挺经典的. 题意是给出三一个字符串s,a,b,求以a开头b结尾的本质不同的字符串数. 由于n不算大,用hash就可以搞,不过这道题是存在复杂度$O(nlogn)$的做法的. 由于要求本质不同,所以可以考虑使用后缀数组来不重复地枚举字符串. 首先用两个不同的其他字符将s,a,b拼起来求后缀数组,这样就可以知道任意两个后缀的lcp了.然后将s中所有b出现的末尾位置置1,求个后缀和suf.将s中所有后缀按名次从小到大存到一个vector里.对于s中的每个后缀,设其…
Codeforces 113 B 题意:有一个母串\(S\)以及两个串\(S_{begin}\)和\(S_{end}\),问\(S\)中以\(S_{begin}\)为开头并且以\(S_{end}\)为结尾的不同子串的个数. 思路1(后缀自动机): 首先肯定要把后缀自动机构建出来(第一次一遍敲对后缀自动机祭),然后我们考虑\(S_{begin}\)(和\(S_{end}\),是对称的,不做考虑)是不是在S中作为一个子串出现,如果出现了那么看它所对应的节点是哪个,打个标记(这个操作就是在自动机上沿着…
题目链接 B. Petr# time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got i…
题目连接: Petr and Permutations 题意:给出一个1到n的序列,Petr打乱了3n次,Um_nik打乱了7n+1次,现在给出被打乱后的序列,求是谁打乱的. 题解:因为给出了一个3*n和一个7*n+1,发现这两个当一个为奇数另一个一定为偶数,所以可以联想和奇偶性质有关.但是这里面要算最短几步能把当前的序列变成1-n.这里我算错~~顺便学了一下如何将置换序列复原. #include<bits/stdc++.h> using namespace std; typedef pair…
题意:初始有一个序列[1,2,...N],一次操作可以将任意两个位置的值互换,Petr做3*n次操作:Alxe做7*n+1次操作.给出最后生成的新序列,问是由谁操作得到的. 分析:一个序列的状态可以归为:由原序列操作奇数次得到(简称奇序列):和操作偶数次(偶序列)得到.显然奇序列中,逆序对的个数为奇数:偶序列中,逆序对的个数为偶.当n为奇数时,3*n为奇,7*n+1为偶:n为偶数时正好相反. 用树状数组或归并排序求逆序对即可. #include<iostream> #include<st…
题目链接:http://codeforces.com/problemset/problem/760/A 题意:日历需要多少列. #include <bits/stdc++.h> using namespace std; ] = {,,,,,,,,,,,}; int main() { int m,d; scanf("%d%d",&m,&d); ]; ; day = day - (-d+); ) ans+=(day/+); ); printf("%d\…
这题真的只能靠直觉了,我没法给出详细证明. 解题思路: 1.交换3n次或者7n+1次,一定会出现一个为奇数,另一个为偶数. 2.用最朴素的方法,将n个数字归位,计算交换次数. 3.判断交换次数是否与3n的奇偶性相同,相同输出Petr: 不相同则一定与7n+1的奇偶性相同,输出Um_nik. 代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; ]; ]; int main(){ ios::sync_wit…
Description\text{Description}Description Given an array a[], swap random 2 number of them for 3n or (7n+1) times.\text{Given an array }a[],\text{ swap random 2 number of them for }3n\text{ or }(7n+1)\text{ times.}Given an array a[], swap random 2 num…
The Meeting Place Cannot Be Changed CodeForces - 982F Petr is a detective in Braginsk. Somebody stole a huge amount of money from a bank and Petr is to catch him. Somebody told Petr that some luxurious car moves along the roads without stopping. Petr…