首先看我对kmp解决周期、前缀与后缀间关系的解释http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.htmlhdu 3336 count the string题意:求给定字符串含前缀的数量abab前缀为aababaabababab中共有六个子串是前缀a a ab ab aba abab所以答案为6利用kmp中的匹配原理可以完美的解决此题a---------d----- -----a---------d i j如上所示,假设两串字符完全相等,next[j]=i,代表s[1...i]==sum[j-i+1....j]... Read More
posted @ 2012-01-05 22:18 Because Of You Views(5724) Comments(0) Diggs(4) Edit
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=15&problem=1266&mosmsg=Submission+received+with+ID+9619336题意:求1~n中不能被给定m个数中任意一个数整除的数的个数Sample Input10 22 320 22 4Sample Output310思想:n-(1~n中至少能被m个数中的一个整除的数个数)解法:容斥原理的思想,多减的数要加回去比如第 Read More
posted @ 2012-01-05 16:25 Because Of You Views(607) Comments(0) Diggs(1) Edit
二分答案,然后用容斥原理求1-mid中与m互质的个数注意二分的上界View Code #include<stdio.h>#include<vector>using namespace std;int m,n;__int64 solve(int r,__int64 n){ vector<int> p; int i; for(i=2;i*i<=r;i++){ if(r%i==0){ p.push_back(i); while(r%i==0) r/=i; } } if(r>1) p.push_bac... Read More
posted @ 2012-01-05 14:29 Because Of You Views(1114) Comments(1) Diggs(0) Edit