$Hdu1381\ Crazy\ Search$
前置芝士 :string 的 基本用法
string s = "hello world" ;
string tmp(s,0,5) ;
cout << tmp << endl ;
上面这一段代码 可以复制粘贴 然后改变 数字。(试试效果
\(string\ tmp(s,i,n);\)
赋初值 也就是说从 $s[i]\ - To - \ s[i+n-1] $
所以既然是这样 应该就有一种比较优秀的做法 \(O(S.length())\)
可海星。
\]
然后用\(map\)统计种类(\(set\)也行的。
#include <bits/stdc++.h>
#define rep(i,j,n) for(register int i=j;i<=n;i++)
#define Rep(i,j,n) for(register int i=j;i>=n;i--)
#define low(x) x&(-x)
using namespace std ;
typedef long long LL ;
const int inf = INT_MAX >> 1 ;
inline LL In() { LL res(0) , f(1) ; register char c ;
#define gc c = getchar()
while(isspace(gc)) ; c == '-' ? f = - 1 , gc : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(gc)) ;
return res * f ;
#undef gc
}
int n ;
int c ;
string s ;
map < string , int > ans ;
inline void Ot() {
cin >> n >> c >> s ;
rep(i,1,s.length()-n+1) {
string tmp(s,i-1,n) ; // from i - 1 to (i - 1 + n -1 )
//if(tmp.length() < n) continue ;
ans[tmp] ++ ;
}
cout << ans.size() << endl ;
}
signed main() {
// freopen("test.in","r",stdin) ;
return Ot() , 0 ;
}
#include <bits/stdc++.h>
#define rep(i,j,n) for(register int i=j;i<=n;i++)
#define Rep(i,j,n) for(register int i=j;i>=n;i--)
#define low(x) x&(-x)
using namespace std ;
typedef long long LL ;
const int inf = INT_MAX >> 1 ;
inline LL In() { LL res(0) , f(1) ; register char c ;
#define gc c = getchar()
while(isspace(gc)) ; c == '-' ? f = - 1 , gc : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(gc)) ;
return res * f ;
#undef gc
}
int n , c ;
string s ;
set < string > st ;
inline void Ot() {
cin >> n >> c >> s ;
rep(i,1,s.length()-n+1) {
string tmp(s,i-1,n) ;
st.insert(tmp) ;
}
cout << st.size() << endl ;
}
signed main() {
// freopen("test.in","r",stdin) ;
return Ot() , 0 ;
}
随机推荐
- STL map的用法介绍!
map对象的定义 使用前添加map头文件,必须分别指明键和值的类型: map<string,int>word_count; map的构造函数: map<k,v>m; 创建一 ...
- 莫(meng)比(bi)乌斯反演--BZOJ2301: [HAOI2011]Problem b
n<=50000个询问,每次问a<=x<=b,c<=y<=d中有多少gcd(x,y)=K的(x,y).a,b,c,d,K<=50000. 这大概是入门题辣..这里记 ...
- springMVC @Value的使用
@Value 功能:将一个SpEL(SpEL:spring表达式类似于ognl)表达式结果映射到功能处理方法的参数上 例子:获取系统参数'java.vm.version'的值给到变量jvmVersio ...
- abs 暴力
Given a number x, ask positive integer y≥2y≥2, that satisfy the following conditions: 1. The absolut ...
- codevs——1019 集合论与图论
1019 集合论与图论 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 集合论与图论对于小松来说 ...
- Python 出现 can't use a string pattern on a bytes-like object
Python 出现 can't use a string pattern on a bytes-like object 学习了:https://www.cnblogs.com/andrewleeeee ...
- Spring中JavaConfig特性
从Spring3開始,增加了JavaConfig特性.JavaConfig特性同意开发人员不必在Spring的xml配置文件里定义bean,能够在Java Class中通过凝视配置bean,假设你讨厌 ...
- 【Android归纳】回调机制在Android中的应用与实战
回调这样的思想在程序中是比較普遍的.有时候可能我们并没有注意到.近期整理了一些对于回调的理解,分享给大家 先上概念...... 什么是回调函数? 回调函数就是一个通过函数指针调用的函数. 假设你把函数 ...
- SpringMVC之application-context.xml,了解数据库相关配置
上一篇SpringMVC之web.xml让我们了解到配置一个web项目的时候,怎样做基础的DispatcherServlet相关配置.作为SpringMVC上手的第一步.而application-co ...
- 9种样式CSS3 渐变button集
<!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/h ...