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\),让你可以拼凑机器,请问最大总性能为多少,且要求输出方案. 题解: 这道题是真的水啊,我不想写太多 ...
随机推荐
- windows重新获取IP
win+r------->cmd------>ipconfig /release (释放ip) ipconfig /renew 重新获取ip
- Android ANR分析(三)
http://www.jianshu.com/p/8964812972be http://stackoverflow.com/questions/704311/android-how-do-i-inv ...
- 七牛:关于图片 EXIF 信息中旋转参数 Orientation 的理解
EXIF(Exchangeable Image File)是 “可交换图像文件” 的缩写,当中包含了专门为数码相机的照片而定制的元数据,可以记录数码照片的拍摄参数.缩略图及其他属性信息,简单来说,Ex ...
- Mysql中文乱码问题完美解决方案
drop database`netctoss_demo` ;CREATE DATABASE `netctoss_demo` CHARACTER SET 'utf8' COLLATE 'utf8_gen ...
- c程序辨别系统是64位 or 32位
#include <stdio.h> int main(void) { int i = 0x80000000; ){ printf("i = %d\n", i); pr ...
- WCF消息拦截,利用消息拦截做身份验证服务
本文参考 http://blog.csdn.net/tcjiaan/article/details/8274493 博客而写 添加对信息处理的类 /// <summary> /// 消 ...
- 网络模拟器WANem使用配置图文教程
转自:http://blog.csdn.net/zm_21/article/details/25810263 WANem简介 由于公司在一些场合需要模拟真实的网络环境,如时延,丢包,抖动等,虽然使用L ...
- TI Zigbee Light Link 参考设计
TI Zigbee Light Link 参考设计 原文出处: http://processors.wiki.ti.com/index.php/Category:ZigBee_Light_Link ...
- Intent.putExtra()传递Object对象或者ArrayList<Object> (转)
Intent传递基本类型相信大家都十分熟悉,如何传递Object对象或者ArrayList<Object>对象呢? 可以通过: (1)public Intent putExtra (Str ...
- codeforce ABBYY Cup 3.0 - Finals (online version) B2. Shave Beaver! 线段树
B2. Shave Beaver! The Smart Beaver has recently designed and built an innovative nanotechnologic a ...