Lightoj 1293 Document Analyzer (map+ Two-point method)

Source: Internet
Author: User


1293-document Analyzer
PDF (中文版) Statistics Forum
Time Limit: 3 second (s) Memory Limit: MB

A leading software development company. As Youare great in coding, most of the critical tasks is allotted for you. You likethe challenge and you feel excited to solve those problems.

Recently your company is developing a project named Documentanalyzer. The This project is assigned a task; Of course a critical task. The task is, is given a document consisting of lowercase letters,numbers and punctuations. You have to analyze the document and separate thewords first. Words is consecutive sequences of lower case letters. Afterlisting the words, in the order same as they occurred in the document, you haveto number them from1, 2, ..., n. After so you have to find the range pandQ (p≤q) such, all kinds of words occur between P >andQ (inclusive). If There was multiple such solutions you had to findthe one where the difference ofp and Q is smallest. If Stillthere is a tie and then find the solution wherep is smallest.

Input

Input starts with an integer T (≤15), denoting the number of test cases.

Each case is denoted by one or more lines denoting adocument. Contains no more than characters. A documentwill contain either lowercase letters or numbers or punctuations. The last lineof a document would contain the word' END ' which is of course not thepart of the document. You can assume that a document would contain between1and 50000 words (inclusive). Words may contain up totencharacters. And a document can contain up to lines.

Output

For each case, print the case number and p and Qas described above.

sampl E Input output for Sample Input

3

1. A case was a case,

2. Case was not a case~

end

a b c d e

end

Span style= "font-size:14px" >[email protected]# $a ^%a a a

b b----B b++ 12b

end

case 1:6 9

case 2:1 5

case 3:5 6

Note

The Dataset is huge, and the use faster I/O methods.


Title Link: http://lightoj.com/volume_showproblem.php?problem=1293


The end value of the interval that covers all English strings is minimized


Title Analysis: First separate English words or letters map into discrete numbers, and then is the two-point method, first determine the smallest right endpoint so that the interval contains all the non-repeating number records at the left and right end of the interval, and then move the end point, if the interval does not contain all the numbers then move the end, This moves the left and right end points repeatedly and updates the interval endpoint value until the legal interval is not found back


#include <cstdio> #include <string> #include <cstring> #include <map>using namespace Std;int     Const MAX = 500005;int Const INF = 0x3fffffff;char S[max];bool hash[max];int a[max];map <string, int> mp;int main () {    int T;    scanf ("%d", &t);        for (int CA = 1; CA <= T; ca++) {mp.clear ();        Map <int, int> H;        Memset (hash, false, sizeof (hash));        memset (A, 0, sizeof (a));        int cnt = 0, num = 0;            while (gets (s)) {string tmp = "";            if (strcmp (S, "END") = = 0) break;            int len = strlen (s);                    for (int i = 0; I <= len; i++) {if (S[i] >= ' A ' && s[i] <= ' z ')                TMP + = S[i];                        else {if (tmp! = "") {if (!hash[mp[tmp])                            {num + +; MP[TMP] = id++;                            HASH[MP[TMP]] = true;                        } a[cnt++] = mp[tmp];                    TMP = "";        }}}} int st = 0, ed = 0, num2 = 0;        int Ansst, ansed, MI = INF;                    while (true) {while (Ed < cnt && Num2 < num) if (h[a[ed++]] + = = 0)            Num2 + +;            if (num2 < num) break;                if (Ed-st < mi) {ansed = ed;                Ansst = st;            Mi = ed-st;        } if (---h[a[st++]] = = 0) num2--;    } printf ("Case%d:%d%d\n", CA, Ansst + 1, ansed); }}


Lightoj 1293 Document Analyzer (map+ Two-point method)

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.