• $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()))

    可海星。

    [STL大法好啊 ]

    然后用(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 ;
    }
    
  • 相关阅读:
    软件开发 [CJOJ 1101] [NOIP 模拟]
    OI中卡常数技巧
    疫情控制 [NOIP2012]
    开车旅行 [NOIP 2012]
    观光公交 [NOIP 2011] [思维推导]
    选择客栈 [NOIP 2011]
    2016级算法期末上机-F.中等·AlvinZH's Fight with DDLs II
    2016级算法期末上机-E.中等·ModricWang's Fight with DDLs II
    2016级算法期末上机-D.简单·AlvinZH's Fight with DDLs I
    2016级算法期末上机-C.简单·Bamboo's Fight with DDLs III
  • 原文地址:https://www.cnblogs.com/qf-breeze/p/10700706.html
Copyright © 2020-2023  润新知