编程大赛-7
|
non-overlapping substrings
|
For a given integer k and a string S consisting of lower letters a..z, find the longest substring s that has at least k non-overlapping occurrences in S and:
- s is prefix of S, (prefix is any leading contiguous part of S) and
- s is a suffix of S, (suffix is any ending contiguous part of S)
Input: (standard input)
+Line 1 contains a number k, 2 ≦ k ≦ 1000000.
+Line 2 contains a string S of a length n, 0 ≦ n ≦ 1000000.
Output: (standard output)
Your program should print out the maximum length of a substring which satisfies the rules.
Example:
For sample input:
3
ababxabaxabab
a correct output format:
2
|
Polygon - internal grid points |
A 1x1 square is moved counterclockwise along the border of a rectilinear polygon with vertices having integer coordinates. The polygon has no holes. The square may be moved by a distance of 1 in any of 4 directions: North, South, West orEast, remaining within the polygon. The square will visit all the edges of the polygon. After completing one counterclockwise circuit of the perimeter, the square returns to its starting position on the last move.
Input: (standard input)
+Line 1 contains a number n, 2≦n≦100000, where n denotes a number of square's moves.
+Line 2 contains a sequence of letters: N, S, W or E - corresponding to each move.
Output: (standard output)
Your program should print out the number of internal grid points within a given polygon.
Example:
For sample input:
32
SNEEESNEEWWNNEENSWWNNWSSWWNNSSSS
a correct output format:
8
Hint: Described polygon is marked grey. The starting and ending position of the square is marked green. There are 8 internal grid points marked red.


浙公网安备 33010602011771号