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\),让你可以拼凑机器,请问最大总性能为多少,且要求输出方案. 题解: 这道题是真的水啊,我不想写太多 ...
随机推荐
- weblogic监控
http://wenku.baidu.com/link?url=tQPQ-dgm7NOkEGj_vemwtsPd6TJ6W3x6_0UBLgw61N982SwPlz-QFxqncsmPGqHwJAEF ...
- Ubuntu16.04 + Win 10 双系统 时间同步,启动项顺序,NumLock指示灯常亮
1. Ubuntu & win10 双系统时间同步: 先在ubuntu下更新一下时间,确保时间无误: sudo apt-get install ntpdate sudo ntpdate tim ...
- js继承的概念
js里常用的如下两种继承方式: 原型链继承(对象间的继承) 类式继承(构造函数间的继承) 由于js不像java那样是真正面向对象的语言,js是基于对象的,它没有类的概念.所以,要想实现继承,可以用js ...
- Solr入门之(4)配置文件solr.xml
<?xml version="1.0" encoding="UTF-8" ?> <!-- This is an example of a si ...
- PL/SQL连接配置
在Oracle安装目录oracle\product\10.2.0\db_2\NETWORK\ADMIN下修改一下三个文件: listener.ora,sqlnet.ora,tnsnames.ora l ...
- css 全局 兼容性问题
css 笔记 第一种:常用的全局CSS属性设置 //参考大型网站,如凤凰网 (1)清除所有的标记的内外边距 body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,p ...
- Windows phone 8.0 本地化遇到的两个问题
基本上来说,按照msdn来讲的,本地化和全球化没有太多的问题,链接如下: http://msdn.microsoft.com/zh-cn/library/windowsphone/develop/ff ...
- TI Zigbee Light Link 参考设计
TI Zigbee Light Link 参考设计 原文出处: http://processors.wiki.ti.com/index.php/Category:ZigBee_Light_Link ...
- Spring中属性文件properties的读取与使用
实际项目中,通常将一些可配置的定制信息放到属性文件中(如数据库连接信息,邮件发送配置信息等),便于统一配置管理.例中将需配置的属性信息放在属性文件/WEB-INF/configInfo.propert ...
- 使用yum来安装或卸载CentOS图形界面包
命令行模式安装图形界面 yum grouplist 检查已安装的组 yum groupinstall "X Window System" yum groupinstall &quo ...