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"