Contact
IOI ' 98
The cows has developed a new interest in scanning the universe outside their farm with Radiotelescopes. Recently, they noticed a very curious microwave pulsing emission sent right from the centre of the Galaxy. They wish to know if the emission are transmitted by some extraterrestrial form of intelligent life or if it's nothing but The usual heartbeat of the stars.
Help the cows-find the Truth by providing a tool to analyze bit patterns in the files they record. They is seeking bit patterns of length A through binclusive (1 <= A <= b <=) that repeat th Emselves most often in each day's data file. They is looking for the patterns, which repeat themselves most often. An input limit tells what many of the most frequent patterns to output.
The Pattern occurrences may overlap, and is patterns that occur at least once is taken into account.
Program Name:contactinput FORMAT
Line 1: |
Three space-separated integers:a, B, N; (1 <= n≤50) |
Lines 2 and Beyond: |
A sequence of as many as 200,000 characters, all 0 or 1; The characters is presented per line and except potentially the last line. |
SAMPLE INPUT (file contact.in)
2 4 1001010010010001000111101100001010011001111000010010011110010000000
In this example, pattern occurs times, and pattern occurs 5 times. The most frequent pattern is XX, with occurrences.
OUTPUT FORMAT
Lines that list, the N highest frequencies (in descending order of frequency), along with the patterns, occur in those F Requencies. Order those patterns by shortest-to-longest and increasing binary number for those of the same frequency. If fewer than N highest frequencies is available, print only those that is.
Print the frequency alone by itself in a line. Then print the actual patterns space separated, six to a line (unless fewer than six remain).
SAMPLE OUTPUT (file contact.out)
23001501 10121001111 000 001100108010070010 10016111 00005011 110 100040001 0011 1100
I am a weak slag, I have been debugging for a long time (at least two hours) ... It's all the wrong!!!!!!! in the output format.
In fact, only need to read, and then according to the requirements of the topic string, there are some basic string operation.
We used the sort artifact and the map artifact.
So after the resolution of the output format, the sky cleared up!
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<map>using namespacestd;intA,b,n,o;map<string,int>K;stringg[10005];intOo;Chars[200555];structlike{intti; stringXu; intLen; intda; BOOL operator< (like L)Const { if(ti==l.ti) {if(Len==l.len)returnDa>L.da; Else returnLen>L.len; } Else returnti<L.ti; }}f[100005];intMain () {Freopen ("contact.in","R", stdin); Freopen ("Contact.out","W", stdout); inti,j; scanf ("%d%d%d",&a,&b,&N); Chardu; while(SCANF ("%c", &du) = =1) { if(du!='0'&&du!='1')Continue; o++; S[o]=du; stringz=""; for(i=o;i>=o-b+1;--i) {stringAa=""; if(i<1) Break; Z+=R[i]; if(Z.length () <a| | Z.length () >b)Continue; for(J=z.length ()-1; j>=0;--j) AA+=Z[j]; if(k[aa]==0) {oo++; G[oo]=AA; } K[aa]++; } } for(i=1; i<=oo;++i) {f[i].ti=K[g[i]]; F[i].len=g[i].length (); intnum=0; for(j=0; J<=g[i].length ()-1;++j) Num=num*2+g[i][j]-'0'; F[i].da=num; F[i].xu=G[i]; } sort (F+1, f+1+oo); intp=0, awa=0; I=oo+1; intlast=0, pp=0; while(p<=N) {i--; if(i<1) Break; if(f[i].ti!=Last ) { Last=F[i].ti; P++; if(p>n) Break; if(awa>0&&pp!=1) printf ("\ n"); AWA++; printf ("%d\n", last); PP=1; } if(pp==1) {cout<<F[i].xu; } Elsecout<<" "<<F[i].xu; PP++; if(pp==7) {pp=1; printf ("\ n"); } } if(pp!=1) printf ("\ n"); return 0;}
*usaco topic sharing--contact