ACM: 限时训练题解-Street Lamps-贪心-字符串【超水】
- 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-贪心-字符串【超水】的更多相关文章
- ACM: 限时训练题解-Rock-Paper-Scissors-前缀和
Rock-Paper-Scissors Rock-Paper-Scissors is a two-player game, where each player chooses one of Roc ...
- ACM: 限时训练题解-Runtime Error-二分查找
Runtime Error Bahosain was trying to solve this simple problem, but he got a Runtime Error on one ...
- ACM: 限时训练题解-Heavy Coins-枚举子集-暴力枚举
Heavy Coins Bahosain has a lot of coins in his pocket. These coins are really heavy, so he always ...
- ACM: 限时训练题解- Travelling Salesman-最小生成树
Travelling Salesman After leaving Yemen, Bahosain now works as a salesman in Jordan. He spends mos ...
- ACM: 限时训练题解-Epic Professor-水题
Epic Professor Dr. Bahosain works as a professor of Computer Science at HU (Hadramout Universit ...
- 课堂限时训练-简易计算器·mini dc
课堂限时训练-简易计算器·mini dc 实验题目 采用后缀表达式法,设计一个建议计算器,实现+.-.*./四种运算. 代码实现 码云链接 关键代码部分及结果如下: 实验分析 首先,分析一下后缀表达式 ...
- 洛谷P2507 [SCOI2008]配对 题解(dp+贪心)
洛谷P2507 [SCOI2008]配对 题解(dp+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1299251 链接题目地址:洛谷P2507 [S ...
- 洛谷P1484 种树&洛谷P3620 [APIO/CTSC 2007]数据备份 题解(堆+贪心)
洛谷P1484 种树&洛谷P3620 [APIO/CTSC 2007]数据备份 题解(堆+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/132 ...
- 「POJ3436」ACM Computer Factory题解
题意: 有很多台机器,可以把物件从一种状态改装成另一种状态,初始全为\(0\),最终状态全为\(1\),让你可以拼凑机器,请问最大总性能为多少,且要求输出方案. 题解: 这道题是真的水啊,我不想写太多 ...
随机推荐
- 从数据库导出数为生成excel表
mysql -umaster -hxx.xx.xx.xx -p -e "set names utf8; use xxxdb;select * from t_order where t_ord ...
- HTTP1.0和HTTP1.1的主要区别是
HTTP/.0协议使用非持久连接,即在非持久连接下,一个tcp连接只传输一个Web对象 HTTP/.1默认使用持久连接(然而,HTTP/.1协议的客户机和服务器可以配置成使用非持久连接)在持久连接下, ...
- CLR via C#(16)--泛型
泛型就像是一个模板,常常定义一些通用的算法,具体调用时再替换成实际的数据类型,提高了代码的可重用性. 一.初识泛型 1. 简单实例 以最常用的FCL中的泛型List<T >为例: stat ...
- jQuery – 3.JQuery的Dom操作
3.1 JQuery的Dom操作 1.使用html()方法读取或者设置元素的innerHTML 2.使用text()方法读取或者设置元素的innerText 3.使用attr() ...
- WPF控件
1:内容控件(Content Controls)2:条目控件(Items Controls)3:文本控件(Text Controls)4:范围控件(Range Controls) 一:内容控件 内容控 ...
- Delphi中的函数指针判断是否为空
delphi函数指针 只有@@p才代表了函数指针本身的地址 assigned(p) 判断是否为空 或者用 @p=nil 来判断函数指针是不是为空 Delphi中的函数指针实际上就是指针,只是在使用 ...
- 湘潭1247 Pair-Pair(树状数组)
分析: 给定n个二元组,求选出两个二元组(可以是同一个)组成一序列其LIS为1,2,3,4的方法数. 分别记为s1, s2, s3, s4 s1,s4对应的情形为a >= b >= c & ...
- go 入门之环境搭建-Windows
网上有很多关于go的环境配置的文章,都没有说出关键点.对于一个新人来说,请使用IDE,而不是sublime text,vim之类的文本编辑器.当然,当你上手之后,可以随便玩. 笔者这里推荐新人使用 L ...
- Macbook Pro安装win7
1.进入OS X系统,在实用工具中打开Boot Camp助理 2.用磁盘工具对磁盘进行分区,将需要安装win7的分区格式化成FAT格式 3.用Boot Camp对磁盘进行分割,然后插入win7的安装光 ...
- [Eclipse] Eclipse is running in a JRE, but a JDK is required
安装Maven后每次启动出现警告信息: Eclipse is running in a JRE, but a JDK is required Some Maven plugins may not wo ...