1. Street Lamps

 

Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is a lamp in a block, it will light it’s block and the direct adjacent blocks. For example, if there is a lamp at block 3, it will light the blocks 2, 3, and 4.

Given the state of the street, determine the minimum number of lamps to be installed such that each block is lit.

Input

 

The first line of input contains an integer T (1 ≤ T ≤   1025) that represents the number of test cases.

The first line of each test case contains one integer N (1 ≤ N ≤ 100) that represents the number of blocks in the street.

The next line contains N characters, each is either a dot ’.’ or an asterisk   ’*’.

A dot represents an empty block, while an asterisk represents a block with a lamp installed in it.

Output

 

For each test case, print a single line with the minimum number of lamps that have to be installed so that all blocks are lit.

Sample Input

Sample Output

3

2

6

0

......

1

3

*.*

8

.*.....*

/*
这题纯水。
*/ #include"iostream"
#include"algorithm"
#include"cstdio"
#include"cstring"
#include"cmath"
#define MX 100 + 5
using namespace std; char s[MX];
bool ss[MX]; int main() {
int T,ans,len;
scanf("%d",&T);
while(T--) {
memset(ss,0,sizeof(ss));
memset(s,0,sizeof(s));
scanf("%d%s",&len,s+1);
ans=0;
for(int i=1; i<=len; i++) {
if(s[i]=='*') {
ss[i-1]=ss[i]=ss[i+1]=1; //把已经照亮的地方标记为 1
}
}
int tot=0;
for(int i=1; i<=len; i++) {
if(ss[i]) { //统计每一个没亮的地方的长度
ans+=(tot+2)/3; //除3 向上取整
tot=0;
}
else tot++;
}
ans+=(tot+2)/3;
printf("%d\n",ans);
}
return 0;
}

  

ACM: 限时训练题解-Street Lamps-贪心-字符串【超水】的更多相关文章

  1. ACM: 限时训练题解-Rock-Paper-Scissors-前缀和

    Rock-Paper-Scissors   Rock-Paper-Scissors is a two-player game, where each player chooses one of Roc ...

  2. ACM: 限时训练题解-Runtime Error-二分查找

    Runtime Error   Bahosain was trying to solve this simple problem, but he got a Runtime Error on one ...

  3. ACM: 限时训练题解-Heavy Coins-枚举子集-暴力枚举

    Heavy Coins   Bahosain has a lot of coins in his pocket. These coins are really heavy, so he always ...

  4. ACM: 限时训练题解- Travelling Salesman-最小生成树

    Travelling Salesman   After leaving Yemen, Bahosain now works as a salesman in Jordan. He spends mos ...

  5. ACM: 限时训练题解-Epic Professor-水题

    Epic Professor   Dr. Bahosain works as a professor of Computer Science at HU (Hadramout    Universit ...

  6. 课堂限时训练-简易计算器·mini dc

    课堂限时训练-简易计算器·mini dc 实验题目 采用后缀表达式法,设计一个建议计算器,实现+.-.*./四种运算. 代码实现 码云链接 关键代码部分及结果如下: 实验分析 首先,分析一下后缀表达式 ...

  7. 洛谷P2507 [SCOI2008]配对 题解(dp+贪心)

    洛谷P2507 [SCOI2008]配对 题解(dp+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1299251 链接题目地址:洛谷P2507 [S ...

  8. 洛谷P1484 种树&洛谷P3620 [APIO/CTSC 2007]数据备份 题解(堆+贪心)

    洛谷P1484 种树&洛谷P3620 [APIO/CTSC 2007]数据备份 题解(堆+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/132 ...

  9. 「POJ3436」ACM Computer Factory题解

    题意: 有很多台机器,可以把物件从一种状态改装成另一种状态,初始全为\(0\),最终状态全为\(1\),让你可以拼凑机器,请问最大总性能为多少,且要求输出方案. 题解: 这道题是真的水啊,我不想写太多 ...

随机推荐

  1. C# 设计模式 提高可维护性的几点原则

    为了提高软件的可维护性,应该遵循以下几点原则: 1.“开放--封闭”原则(OCP) 一个软件实体应该对扩展开放,对修改封闭. 2.里氏代换原则(LSP) 子类型必须能替换她们的基类型,反过来则不成立. ...

  2. ASP.NET Web API 上传文件

    HTML表单: <form id="form1" method="post" enctype="multipart/form-data" ...

  3. 从 Eclipse 迁移至 Android Studio

    从 Eclipse 迁移至 Android Studio 本文内容 Android Studio 基础知识 迁移先决条件 将项目导入 Android Studio 后续步骤 将项目迁移至 Androi ...

  4. Mongo DB Study: first face with mongo DB

    Mongo DB Study: first face with mongo DB 1.  study methods: 1.  Translate: I am the mongo DB organiz ...

  5. 堆栈C实现

    标准C语言没有像C++那样可以直接调用的STL容器,所以在c语言中实现容器功能就得自己去定义堆栈结构: stack.h /************this head file defines a st ...

  6. iOS 随记

    UIImage 走缓存 + (UIImage *)imageNamed:(NSString *)name; 不走缓存 + (UIImage *)imageWithContentsOfFile:(NSS ...

  7. 第二十篇:在SOUI中使用分层窗口

    从Windows 2K开始,MS为UI开发引入了分层窗口这一窗口风格.使用分层窗口,应用程序的主窗口可以是半透明,也可以是逐点半透明(即每一个像素点的透明度可以不同). 可以说,正是因为有了分层窗口, ...

  8. 封装自己的printf函数

    #include <stdio.h> #include <stdarg.h> //方式一 #define DBG_PRINT (printf("%s:%u %s:%s ...

  9. Android基本认识

    AndroidManifest.xml file missing! 是因为开始想当然的用中文当project名 no launcher activity found 第一次运行出了点问题,no lau ...

  10. 通过PID获取进程路径的几种方法

    通过PID获取进程路径的几种方法 想获得进程可执行文件的路径最常用的方法是通过GetModuleFileNameEx函数获得可执行文件的模块路径这个函数从Windows NT 4.0开始到现在的Vis ...