zoukankan      html  css  js  c++  java
  • 【例题 8-15 UVA

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    枚举第一段的范围[0..i] (0<=i

    【代码】

    /*
      	1.Shoud it use long long ?
      	2.Have you ever test several sample(at least therr) yourself?
      	3.Can you promise that the solution is right? At least,the main ideal
      	4.use the puts("") or putchar() or printf and such things?
      	5.init the used array or any value?
      	6.use error MAX_VALUE?
      	7.use scanf instead of cin/cout?
      	8.whatch out the detail input require
    */
    /*
        一定在这里写完思路再敲代码!!!
    */
    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 1e5;
    
    int T,s,n,bo[N+10],a[N+10],f[N+10],cnt[N+10],kai[N+10],jie[N+10];
    
    int ff(int x){
        if (f[x]!=x) return ff(f[x]);
        else return x;
    }
    
    void init(){
        memset(jie,255,sizeof jie);
        memset(bo,0,sizeof bo);
        memset(kai,0,sizeof kai);
    
        int l = 1;
        for (int i = 1;i <= n;i++){
            while (bo[a[i]]){
                bo[a[l]] = 0;
                l++;
            }
            if (i-l+1==s){
                if (jie[l-1]!=-1){
                    int r1 = ff(jie[l-1]),r2 = ff(l);
                    f[r1] = r2;
                    cnt[r2] += cnt[r1];
                }
                kai[l] = 1;
                jie[i] = l;
            }
    
            bo[a[i]] = 1;
        }
        if (n-l+1<s) kai[l] = 1;
        for (int i = l+1;i <= n;i++) kai[i] = 1;
    }
    
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
        cin >> T;
        while (T--){
            cin >> s >> n;
            for (int i = 1;i <= n;i++) cin >> a[i];
            for (int i = 1;i <= n;i++) f[i] = i,cnt[i] = 1;
    
            init();
    
            memset(bo,0,sizeof bo);
            int ans = 0;
            for (int i = 0;i < s;i++){
                if (i<=n && i>=1 && bo[a[i]]) break;
                if (i>=n) {
                    ans++;
                    continue;
                }
                if (kai[i+1]){
                    int r = ff(i+1);
                    if (n-cnt[r]*s-i<s){
                        ans++;
                    }
                }
                if (i>=1 && i <= n) bo[a[i]] = 1;
            }
            cout << ans << endl;
        }
    	return 0;
    }
    
    
  • 相关阅读:
    hdu2155 小黑的镇魂曲(dp)
    hdu2155 小黑的镇魂曲(dp)
    hdu2158 最短区间版大家来找碴
    hdu2158 最短区间版大家来找碴
    hdu2102 水搜索
    hdu2102 水搜索
    hdu 2058 枚举区间和个数
    hdu 2058 枚举区间和个数
    hdu4982 暴搜+剪枝(k个数和是n,k-1个数的和是平方数)
    hdu4982 暴搜+剪枝(k个数和是n,k-1个数的和是平方数)
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8196093.html
Copyright © 2011-2022 走看看