Usaco 3.2 Contact

Source: Internet
Author: User

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 b inclusive (1 <= A <= b <=) that repeat T Hemselves 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

————————————————————————————————————————————————
A common dictionary tree application, sorting out the language details ...
One is the type of the system itself can not overload the operator, to struct a type
There is the output format of this problem "If anyone can see my konjac konjac ..."
Six a row, then a short string in front, long string in the back, the same length of the string is the dictionary order
1 /*2 Id:ivorysi3 prog:contact4 lang:c++5 */6#include <iostream>7#include <cstdio>8#include <cstring>9#include <algorithm>Ten#include <queue> One#include <Set> A#include <vector> - #defineSiji (i,x,y) for (int i= (x); i<= (y); ++i) - #defineGongzi (j,x,y) for (int j= (x); j>= (y);--j) the #defineXiaosiji (i,x,y) for (int i= (x);i< (y); ++i) - #defineSigongzi (j,x,y) for (int j= (x);j> (y);--j) - #defineINF 0x7fffffff - #defineMAXN 400005 + #defineIvorysi - #defineMo 97797977 + #defineHa 974711 A #defineBA 47 at #defineFi first - #defineSe Second - //#define PIS pair<int,string> - using namespacestd; -typedefLong Longll; - inttree[100005]; in strings; - intA,b,n; to structPiS { +     intFirststringsecond; - }; the BOOL operator<(PiS C,pis d) { *     if(c.fi!=d.fi)returnc.fi<d.fi; $     Else if(C.se.length ()!=d.se.length ())returnC.se.length () >d.se.length ();Panax Notoginseng     Else returnc.se >d.se; - }  thePriority_queue<pis>MQ; + voidDfsintUintTstringstr) { A     if(T&GT;B)return; the     if(T>=a && tree[u]!=0) { + Mq.push ((PiS) {tree[u],str}); -     } $DFS (u<<1, t+1, str+"0"); $DFS (u<<1|1, t+1, str+"1"); - } - voidsolve () { thescanf"%d%d%d",&a,&b,&n); -     stringTM;Wuyi      while(CIN&GT;&GT;TM) s+=TM; the     intt=s.length (); -Xiaosiji (I,0, T) { Wu         inttmp=1; -         intL=min (b,t-i); AboutXiaosiji (J,0, L) { $             if(s[i+j]=='0') tree[tmp<<=1]++; -             ElseTree[tmp= (tmp<<1)+1]++; -         } -     } ADfs1,0,""); +      while(n>0) { the         intCnt=0; -PiS p=mq.top (); Mq.pop (); $printf"%d\n%s", P.fi,p.se.c_str ()); the++CNT; the         if(Mq.empty ()) {Puts (""); Break;} the          while(Mq.top (). fi==p.fi) { the             if(cnt==6) {puts (""); cnt=0;} -             Elseprintf" "); inprintf"%s", Mq.top (). SE.C_STR ()); the Mq.pop (); the++CNT; About         } thePuts""); the--N; the     } + } - intMainintargcChar Const*argv[]) the {Bayi #ifdef Ivorysi theFreopen ("contact.in","R", stdin); theFreopen ("Contact.out","W", stdout); - #else -Freopen ("f1.in","R", stdin); the #endif the solve (); the}

Usaco 3.2 Contact

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.