NetEase C + + face test--place Street lamp

Source: Internet
Author: User

Little Q is designing a street lamp placement scheme for a road of length n.

To make the problem easier, small Q treats the road as n squares, where it needs to be illuminated. Indicates that the barrier lattice that does not need to be illuminated is denoted by ' X '.

Small q now to set some street lights on the road, for the position of the street lamp, this lamp can illuminate pos-1, POS, pos + 1 of these three positions.

Little Q hopes to place as few streetlights as possible to illuminate all '. ' Area, I hope you can help him calculate the minimum number of lights required.

Input Description:
The first line of the input contains a positive integer t (1 <= T <= 1000), indicating the number of test cases
Next every two lines of a test data, the first line is a positive integer n (1 <= n <= 1000), which represents the length of the road.
The second line, a string s, represents the construction of a road, containing only '. ' and ' X '.



Output Description:
For each test case, the output of a positive integer indicates the minimum number of lights required.

Input Example 1:
23.x.11 ... Xx.... Xx

Output Example 1:
13


#include <bits/stdc++.h>using namespace Std;typedef long long ll;string s;const int maxn = 1010;int Bits[maxn];int m Ain () {    int T;    scanf ("%d", &t);    int Len;    while (t--)    {        scanf ("%d", &len);        cin>>s;        memset (bits,0,sizeof (bits));        for (int i=0;i<len;i++)        {            if (s[i]== '. ') bits[i]=0;            else bits[i] = 1;        }        int ans = 0;        for (int i=0;i<len;i++)        {            if (bits[i]) continue;            else            {                ans++;                Bits[i] = 1;                BITS[I+1] = 1;                BITS[I+2] =1;            }        }       for (int i=0;i<len;i++)         //   printf ("%d", bits[i]);        cout<<endl;        printf ("%d\n", ans);}    }

  

NetEase C + + face test--place Street lamp

Related Article

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.