Lightoj 1389-scarecrow (greedy AH)

Source: Internet
Author: User

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


Taso owns a very long field. He plans to grow different types of crops in the upcoming growing season. The area, however, are full of crows and Taso fears that they might feeds on the most of the crops. For this reason, he had decided to place some scarecrows at different locations of the field.

The field can be modeled as a 1 x N grid. Some parts of the field is infertile and that means you cannot grow all crops on them. A scarecrow, when placed in a spot, covers the cell to its immediate left and right along with the cell it's on.

Given the description of the field, what's the minimum number of scarecrows that needs to being placed so and all the Usefu L section of the field is covered? Useful section refers to cells where crops can is grown.

Input

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

Each case is starts with a line containing an integer N (0 < N <). The next line contains N characters that describe the field. A dot (.) indicates a crop-growing spot and a hash (#) indicates a infertile region.

Output

For each case, print the case number and the number of scarecrows that need to be placed.

Sample Input Output for Sample Input

3

3

.#.

11

...##....##

2

##

Case 1:1

Case 2:3

Case 3:0


Test instructions

Each scarecrow can cover his own point and the left and right two points, using a minimum of straw to cover all the points that can be planted ('. ') );

The code is as follows:

#include <cstdio> #include <cstring>int main () {    int t;    int n;    Char s[147];    int cas = 0;    scanf ("%d", &t);    while (t--)    {        scanf ("%d", &n);        scanf ("%s", s);        int len = strlen (s);        int ans = 0;        for (int i = 0; i < n; i++)        {            if (s[i] = = ' # ')                continue;            if (s[i] = = '. ')            {                ans++;            }            i + = 2;        }        printf ("Case%d:%d\n", ++cas,ans);    }    return 0;}


Lightoj 1389-scarecrow (greedy AH)

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.