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