UVa 12174 (sliding window) Shuffle

Source: Internet
Author: User
Tags shuffle

First, preprocess the number of front s that end with each count to make a 1~s arrangement.

You can use the CNT array to record the number of occurrences of each number and how many different numbers appear with a variable record.

Then enumerate each possible case, that is, the position where the first song appears, taking into account the incomplete sequence.

Code is not long, but that OK array to write a bit of egg ache, because to consider the existence of incomplete sequence, changed for a long time to change.

1#include <cstdio>2#include <cstring>3#include <cassert>4 5 Const intMAXN =100000+Ten;6 intA[MAXN], S, N, CNT[MAXN *2];7 BOOLOK[MAXN *3];8 9InlineBOOL inch(intx) {returnX >=1&& x <=N;}Ten  One intMain () A { -     //freopen ("In.txt", "R", stdin); -  the     intT scanf"%d", &T); -      while(t--) -     { -scanf"%d%d", &s, &n); +Memset (A,-1,sizeof(a)); -          for(inti =1; I <= N; i++) scanf ("%d", &a[i]); +memset (CNT,0,sizeof(CNT)); A         //memset (OK, false, sizeof (OK)); at         inttot =s; -          for(inti =1; I < n + S; i++) -         { -             if(inch(i-s)) {cnt[a[i-s]]--;if(!cnt[a[i-s]]) tot--; } -             Elsetot--; -             if(inch(i)) {cnt[a[i]]++;if(Cnt[a[i]] = =1) tot++; } in             Elsetot++; -Ok[i] = tot = =s; to         } +  -         intAns =0; the          for(intx =1-S; X <=0; X + +) *         { $             BOOLFlag =true;Panax Notoginseng              for(inti = x; i < n+s; i + =s) -             { the                 if(I <=0)Continue; +                 if(!ok[i]) {flag =false; Break; } A             } the             if(flag) +ans++; -         } $  $printf"%d\n", ans); -     } -  the     return 0; -}
code June

UVa 12174 (sliding window) Shuffle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.