1941. Scary Martian Word
The problem is that a 3-length string is considered a Martian letter (ASCII 33-122), giving a word that Mars believes is scary (made up of the Martian alphabet)
And then I'll give you an article asking the number of words the Martians think is scary (can be ordered)
Well, at first test instructions understand wrong ... And then it's wrong.
God said ... is a double-ended queue
And then I wrote it and I felt really right about it.
Well, overconfidence, the beginning ignores a condition.
Practice, because it's three words 122+122*10+122*100 is almost there.
Then hash. Array tags,
Too lazy to write ...
Paste code ...
#include <iostream>#include<cstring>#include<cstdio>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<queue>#include<stack>#include<Set>#include<string>#include<sstream>using namespaceStd;typedefLong Longll;Const DoubleESP = 10e-8;Const intMAXN =2000000+Ten;intVIS[MAXN];intNUM[MAXN];intARR[MAXN];intN;Charword[maxn*3+1];intMain () {//freopen ("Input.txt", "R", stdin); intAns =0; memset (num,0,sizeof(num)); N=0; Gets (word); intLen =strlen (word); for(inti =0; I < len;i+=4){ inttt = (word[i]- -) + (word[i+1]- -)*Ten+ (word[i+2]- -)* -; NUM[TT]++; if(Num[tt] = =1) {n++; }} gets (word); Len=strlen (word); memset (arr,-1,sizeof(arr)); intCNT =0; for(inti =0; I < len;i+=4){ inttt = (word[i]- -) + (word[i+1]- -)*Ten+ (word[i+2]- -)* -; if(Num[tt]) {arr[cnt++] =tt; } } intL =0; intR =0; memset (Vis,0,sizeof(VIS)); intnn =0; while(L < CNT && R <CNT) { if(Arr[r]! =-1) {vis[arr[r]]++; if(Vis[arr[r]] = =Num[arr[r]]) {NN++; }Else if(vis[arr[r]) >num[Arr[r]]) { while(L < CNT && Arr[l]! =Arr[r]) { if(Vis[arr[l]] = =Num[arr[l]]) {NN--; } vis[Arr[l]]--; L++; } vis[Arr[l]]--; L++; } if(NN = =N) {ans++; VIS[ARR[L]]--; NN--; L++; } R++; }Else{nn=0; memset (Vis,0,sizeof(VIS)); R++; L=R; }} printf ("%d\n", ans); return 0;}
Do not write the comments are really not good programmers ...
1941. Scary Martian Word