HDU4821
来源:互联网 发布:51单片机isp下载 编辑:程序博客网 时间:2024/04/30 11:06
HASH后就是一个简单的线性统计了
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <queue>#include <algorithm>#include <vector>#include <cstring>#include <stack>#include <cctype>#include <utility> #include <map>#include <string> #include <climits> #include <set>#include <string> #include <sstream> #include <ctime>#include <bitset>#include <iomanip>//#pragma comment(linker, "/STACK:102400000,102400000")using std::priority_queue;using std::vector;using std::swap;using std::stack;using std::sort;using std::max;using std::min;using std::pair;using std::map;using std::string;using std::cin;using std::cout;using std::set;using std::queue;using std::string;using std::stringstream;using std::make_pair;using std::getline;using std::greater;using std::endl;using std::multimap;using std::deque;using std::unique;using std::lower_bound;using std::random_shuffle;using std::bitset;using std::upper_bound;using std::multiset;using std::ios;using std::make_heap;using std::push_heap;using std::pop_heap;typedef long long LL;typedef unsigned long long ULL;typedef unsigned UN;typedef pair<int, int> PAIR;typedef multimap<int, int> MMAP;typedef long double LF;const int MAXN(100010);const int MAXM(10010);const int MAXE(2100010);const int MAXK(6);const int HSIZE(13131);const int SIGMA_SIZE(26);const int MAXH(18);const int INFI((INT_MAX-1) >> 1);const ULL BASE(31);const LL LIM(1e13);const int INV(-10000);const int MOD(1000000007);const double EPS(1e-7);const LF PI(acos(-1.0));template<typename T> inline bool checkmax(T &a, T b){if(b > a) { a = b; return true;} return false;}template<typename T> inline bool checkmin(T &a, T b){if(b < a) { a = b; return true;} return false;}template<typename T> inline T ABS(T a){return a < 0? -a: a;}template<typename T> inline bool EZ(T a){return ABS(a) < EPS;}char str[MAXN];map<ULL, int> mp[MAXN];ULL H[MAXN], XP[MAXN];ULL getV(int ind, int l){return H[ind]-H[ind+l]*XP[l];}int main(){int m, l;XP[0] = 1;for(int i = 1; i <= 100000; ++i) XP[i] = XP[i-1]*BASE;while(~scanf("%d%d", &m, &l)){scanf("%s", str);int len = strlen(str);H[len] = 0;for(int i = len-1; i >= 0; --i)H[i] = H[i+1]*BASE+str[i]-'a'+1;int ans = 0;int ml = m*l;for(int i = 0; i < l && i+ml <= len; ++i){mp[i].clear();int star = i;for(int j = 0; j < m; ++j, star += l){ULL val = getV(star, l);if(mp[i].count(val)) ++mp[i][val];else mp[i].insert(make_pair(val, 1));}if(mp[i].size() == m) ++ans;}int tml = l*(m-1);for(int i = l; i+ml <= len; ++i){int ti = i%l;ULL val = getV(i-l, l);--mp[ti][val];if(mp[ti][val] == 0) mp[ti].erase(val);val = getV(i+tml, l);if(mp[ti].count(val)) ++mp[ti][val];else mp[ti].insert(make_pair(val, 1));if(mp[ti].size() == m) ++ans;}printf("%d\n", ans);}return 0;}
1 0
- HDU4821
- HDU4821 String
- HDU4821 字符串hash
- hdu4821 字符串哈希
- hdu4821 字符串hash
- hdu4821 string (字符串Hash)
- HDU4821字符串哈希
- hdu4821 字符串 hash (bkdrhash)
- hdu4821 String 字符串hash(bkdrhash)
- HDU4821-字符串哈希模板
- hdu4821 string 字符串 哈希处理
- HDU4821(2013 Asia Regional Changchun - I)
- hdu4821 String (字符串hash + map)
- 字符串hash+hdu4821(2013长春现场赛)
- 编程心得
- 网站的高性能架构
- 避免APP常见错误
- Eclipse
- Android学习记录(5)—在java中学习多线程下载之断点续传②
- HDU4821
- JVM常用分析命令与工具
- iframe 包含高度长度100%
- windows batch file 实现 tex 文件 的双档、单档(double column, single column)分别编译
- linux查找文件命令find
- 【原】解决PS1的显示问题,busybox的/u /h特殊字符解析问题
- Native开发与JNI机制详解
- android 开发环境搭建
- JS 将select和text表单项替换为普通文本