$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 ;
}
随机推荐
- NYOJ-568/1012//UVA-12299RMQ with Shifts,线段树单点更新+区间查询
RMQ with Shifts 时间限制:1000 ms | 内存限制:65535 KB 难度:3 -> Link1 <- -> Link2 <- 以上两题题意是一样 ...
- <<编程之美>> -- 队列中取最大值操作的问题
不得不说编程之美是一本好书,虽然很多题目在做acm中的过程中遇到过,不过还是有很多值得思考的地方 这是今天在编程之美上看到的一个问题,对于栈转化成队列的一个思考 平时都太过依赖c++内函数库中的栈和队 ...
- 「CodePlus 2017 11 月赛」Yazid 的新生舞会
n<=500000的数字,问有多少个区间的众数出现次数严格大于区间长度的一半. 这么说来一个区间就一个众数了,所以第一反应是枚举数字,对下标进行处理.然后没有第二反应.很好. 在枚举一个数字的时 ...
- hdu_1028_Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- css3自定义流动条
<style> .item { height: 180px; overflow: auto; width: 180px; float: left; margin: 11px; box-sh ...
- <a href="ip地址" target=""_blank">a里面的target</a>
HTML <a> 标签的 target 属性 定义和用法 <a> 标签的 target 属性规定在何处打开链接文档. 如果在一个 <a> 标签内包含一个 targe ...
- 计蒜客15430 XOR Queries(Trie处理位运算问题)
题意: 给出一个长度为n的数组C,回答m个形式为(L, R, A, B)的询问, 含义为存在多少个不同的数组下标k属于[L, R]满足C[k] XOR A >= B(式中XOR为异或运算). T ...
- 选择器的使用(not选择器)
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta ...
- CentOS 7 防火墙开启了哪些服务和端口?
过滤封包功能的 netfilter 已经内建在 CentOS 7 的内核,但是配置 netfilter 的界面程式 firewalld 却未必有安装,不论是否已经安装,都可以执行下面的安装指令: yu ...
- Android Studio 1.x 使用问题汇总
Android Studio是谷歌于13年I/O大会推出的Android开发环境,基于IntelliJ IDEA. 类似 Eclipse ADT,Android Studio 提供了集成的Androi ...