PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000076. Bù nhìn giữ đồng (Scarecrow)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Bù nhìn giữ đồng (Scarecrow)
Scarecrow
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A field consists of consecutive cells, each either fertile (.) or infertile (#). A scarecrow placed on any cell (including an infertile cell) protects its own cell and its immediate left and right neighbors, if present. Infertile cells need not be protected. Find the minimum number of scarecrows needed to protect every fertile cell.
Input
The first line contains . The second line contains exactly characters, each . or #, in left-to-right order.
Output
Print the minimum number of scarecrows.
Subtasks
- Subtask 1 (20 points): ; every character belongs to
{., #}. - Subtask 2 (30 points): ; every character belongs to
{., #}. - Subtask 3 (50 points): ; every character belongs to
{., #}.
Examples
Input
11
...##....##
Output
3
Explanation
Place one scarecrow at cell to cover cells –. The fertile block at cells – needs two more, for example at cells and . Thus the minimum is .