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

.*.....*

 

是的,这是在codeforce上面的一道题,当时写的时候思路和官方给的思路一模一样,可是还是有一些细节没有注意到,比如当字符串是str + 1输入时是可以取到长度len的,for循环中忘记

加上等号了,最近的刷题也不是很顺利,不知道究竟是怎么搞的,可能是写的时候太快的,虽然每道题都写了一遍,可惜都没几个对的,全是都死在了细节上面,以后呀以此为戒,切记!

对了,顺便提醒自己一下,在遇到这种需要改动题目给定条件的时候一定要复制一个改变用的数组来标记,不然可能会自己都不知道错在哪里,希望以后不再犯。

2016-07-26 切记

  1. #include<cstdio>
  2. #include<algorithm>
  3. #include<string>
  4. #include<cstring>
  5. #include<queue>
  6. using namespace std;
  7.  
  8. const int MX = 150;
  9. int sign[MX];
  10. int n;
  11. char str[MX];
  12.  
  13. int main() {
  14. //freopen("input.txt", "r", stdin);
  15. int cas;
  16. while (scanf("%d", &cas) != EOF) {
  17. while (cas--) {
  18. scanf("%d %s", &n, str + 1);
  19. memset(sign, 0, sizeof(sign));
  20. for (int i = 1; i <= n; i++) {
  21. if (str[i] == '*') {
  22. sign[i] = sign[i - 1] = sign[i + 1] = 1;
  23. }
  24. }
  25. int ans = 0;
  26. for (int i = 1; i <= n - 2; i++) {
  27. if (sign[i] == 0 && sign[i + 1] == 0 && sign[i + 2] == 0) {
  28. sign[i] = sign[i + 1] = sign[i + 2] = 1;
  29. ans++;
  30. }
  31. }
  32. for (int i = 1; i <= n - 1; i++) {
  33. if (sign[i] == 0 && sign[i + 1] == 0) {
  34. sign[i] = sign[i + 1] = 1;
  35. ans++;
  36. }
  37. }
  38. for (int i = 1; i <= n; i++) {
  39. if (sign[i] == 0) {
  40. sign[i] = 1;
  41. ans++;
  42. }
  43. }
  44. printf("%d\n", ans);//直接的暴击解决,看到有人喜欢用动态规划,我其实并不想那么多,就用自己的第一感觉做题是最好的
  45. }
  46. }
  47. return 0;
  48. }

Codeforce - Street Lamps的更多相关文章

  1. ACM: 限时训练题解-Street Lamps-贪心-字符串【超水】

    Street Lamps   Bahosain is walking in a street of N blocks. Each block is either empty or has one la ...

  2. 18春季训练01-3/11 2015 ACM Amman Collegiate Programming Contest

    Solved A Gym 100712A Who Is The Winner Solved B Gym 100712B Rock-Paper-Scissors Solved C Gym 100712C ...

  3. 2015 ACM Amman Collegiate Programming Contest 题解

    [题目链接] A - Who Is The Winner 模拟. #include <bits/stdc++.h> using namespace std; int T; int n; s ...

  4. 【硬件模块】华为NBIOT 使用记录

    From: https://liudongdong1.github.io/ 1. background Low power wide area network (LPWAN) has become a ...

  5. codeforce 985B Switches and Lamps(暴力+思维)

    Switches and Lamps time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  6. codeforce Gym 100425E The Street Escalator(期望,线性递推)

    算数学期望,每个人都可以分开来考虑.Xi表示第i个人跑到另外一边的次数. Xi服从二项分布.概率的和是个二项式,(p+1-p)^T,把二项式展开,p的偶次项是留在原来那一边的概率. 可以用((a+b) ...

  7. 申请邓白氏编码的时候总是提示 Enter a valid Street Address 怎么办?

    今天要申请一个苹果开发者公司(Company)账号,然后需要邓白氏编码,然后填写企业的基本信息.其中对于Street Address认真的对照着中文翻译为如下格式: Kang Hesheng buil ...

  8. 【USACO 2.2】Party Lamps

    四种开关,n盏灯,1:改变所有灯状态,2:改变奇数灯状态,3:改变偶数灯状态,4:改变3k+1灯状态 给你按开关的总次数c和部分灯限制条件(开或关),一开始都是开着的.($c \leq 10000,n ...

  9. Codeforce Round #216 Div2

    e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...

随机推荐

  1. vim、gvim加载文件慢

    1. strace -f -T -o vim.strace vim 2. vim --startuptime "vim-time.txt" 3. gvim -f

  2. 【JAVA解析XML文件实现CRUD操作】

    一.简介. 1.xml解析技术有两种:dom和sax 2.dom:Document Object Model,即文档对象模型,是W3C组织推荐的解析XML的一种方式. sax:Simple API f ...

  3. SQL在INNER JOIN时,也可以将子查询加入进来

    这个语法有点神奇,记下. 但觉得用处有限吧. mysql> SELECT a.account_id, a_cust_id, a.open_date, a.product_cd -> FRO ...

  4. 查看MYSQL中数据表占用的空间

    由于数据太大了.所以MYSQL需要瘦身,那前提就是需要知道每个表占用的空间大小. 首先打开指定的数据库: use information_schema; 如果想看指定数据库中的数据表,可以用如下语句: ...

  5. AngularJS讲义 - 作用域

    什么是作用域? Angular中作用域(scope)是模板以及工作的上下文环境,作用域中存放了应用模型和视图相关的回调行为.作用域是层次化结构的与相关联的DOM结构相对应.作用域可以观察表达式以及传播 ...

  6. Oracle里SID、SERVICE_NAME

    本文仅用作备忘,无实际指导意义,逻辑略混乱. 1.命令show parameter name; SQL> show parameter name; NAME TYPE VALUE ------- ...

  7. 攻城狮在路上(叁)Linux(十五)--- 文件与目录的默认权限与隐藏权限

    一.文件默认权限:umask <==需要被减去的权限. 1.umask指的是当前用户在新建文件或者目录时的默认权限,如0022; 2.默认情况下,用户创建文件的最大权限为666; 创建目录的最大 ...

  8. C# SMTP邮件发送 分类: C# 2014-07-13 19:10 334人阅读 评论(1) 收藏

    邮件发送在网站应用程序中经常会用到,包括您现在看到的博客,在添加评论后,系统会自动发送邮件通知到我邮箱的,把系统发送邮件的功能整理了下,做了一个客户端Demo,希望对有需要的童鞋有所帮助: 核心代码: ...

  9. 兼容所有浏览器的JS动态显示当前日期时间

    <script type="text/javascript"> function show_cur_times(){ //获取当前日期 var date_time = ...

  10. C语言中的static 详细分析

    转自:http://blog.csdn.net/keyeagle/article/details/6708077/ google了近三页的关于C语言中static的内容,发现可用的信息很少,要么长篇大 ...