Regionals >> europe-central >>7325-book Borders "Analog"

Source: Internet
Author: User

Europe-central >>7325-book Borders

Topic Links: 7325

The main topic: give you a string (including spaces), each line of x characters, the word is arranged in, the word can not be broken, ask the length of the first word in each line, pay attention to adding a space

Topic Idea: Direct simulation. The first for traversal [a, b], and the second roughly n/A. The complexity is probably nlogn.
Open two arrays, v[i] record I where the word begins, E[v[i]] records the end position of the word where I belong.
And then every time you judge the end of the line, where it is. If you are in the middle of two words, start the word as the next line, or start the next word as the next line

To calculate the length of a word only e[v[i] []-v[i] can be.

The meanings expressed by V and E are as follows

Here's the code:

#include <bits/stdc++.h>#define MST (a) memset (A,0,sizeof (a))#define FOR (i,n) for (int i = 0; i < n; i++)#define INF 1e9#define EPS 1e-10using namespace STD;typedef Long Longll vector <int>Vecintv[500005];inte[500005];intMain () {stringS while(Getline (Cin, s)) {intLen = S.size ();intRET =1; for(inti =0; i < Len; i++) {if(S[i] = ="') {E[ret] = i; RET = i +2; }Elsev[i+1] = RET; } E[ret] = Len;intb;scanf("%d%d", &a,&b); GetChar (); for(inti = A; I <= b; i++) {intAns = e[v[1]]-v[1] +1; for(intf = i; f < Len; )            {if(S[f-1] =="') {ans + = e[v[f +1]]-v[f +1] +1; F = v[f +1] + I-1; ans++;Continue; }if(f >= V[f] && F < e[v[f])//In the middle{ans + = e[v[f]]-v[f] +1; f = v[f] + i-1; }Else if(f = = E[v[f]])//At the end{ans + = e[v[f +2]]-v[f +2] +1; F = v[f +2] + I-1;            } ans++; }printf("%d\n", ans); }    }return 0;}/*its a long-to-the- top If you wanna Rock n roll*/ 

Regionals >> europe-central >>7325-book Borders "Analog"

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.