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\),让你可以拼凑机器,请问最大总性能为多少,且要求输出方案. 题解: 这道题是真的水啊,我不想写太多 ...
随机推荐
- 与你相遇好幸运,My Toolkit of Nodejs
>测试:restler.mocha.assert.request.request-promise >安装:nrm >运维:pm2.node-gyp >开发:nodemon.in ...
- Delphi中exit、break、continue等跳出操作的区别
Delphi中表示跳出的有break,continue,abort,exit,halt,runerror等 1.break 强制退出最近的一层循环(注意:只能放在循环里:而且是只能跳出最近的一层循环) ...
- android 入门-android Studio git 克隆
最后是完成 以上是如何从android studio Git 克隆Github的项目
- 微软改名部再次大显神威——ASP.NET 5改名ASP.NET Core 1.0
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:在计算机科学领域只有两件难事:缓存不可用和命名.--Phil Karlton 今天,S ...
- 监听报错 TNS-00525: Insufficient privilege for operation 11gR2 + 连接报错ORA-12537: TNS:connection closed
1.TNS-00525: Insufficient privilege for operation Started with pid= Listening on: (DESCRIPTION=(ADDR ...
- Git提交基本流程
在无其他分支,大家都向同一分支master分支提交代码的情况下: 1.查看本地对代码的修改情况,即可以被提交的修改记录 git status 其中被修改过的文件标识为modified,删除的文件del ...
- Printf()输出格式控制(转)
int printf(const char *format,[argument]); format 参数输出的格式,定义格式为: %[flags][width][.perc] [F|N|h|l]typ ...
- C#联通新版验证码识别的实现
以前写了篇 联通充值卡自动充值的实现,最近发现联通官网改版了,随便看了下发现新版的验证码和以前的不同,发了点时间研究了下他的识别码,它现在的验证码如下 现在将识别步骤说下 1,转换灰度图片 2,清除2 ...
- Java 程序 ——感想
也许大家也有过这样的经历,我这的是受够了: 我们的专业选修课java课上老师留了一个作业,说做完了这个,就不用参加考试了,侥幸于懒惰的心理带领着我,光荣地接受了这个任务,而且按着老师的要求,不断地完善 ...
- jq中.prop()与attr()的区别
一,定义 prop() 方法设置或返回被选元素的属性和值.prop() 方法应该用于检索属性值 attr() 方法设置或返回被选元素的属性和值.如需检索 HTML 属性,请使用 attr() 方法代 ...