LightOJ - 1389 Scarecrow (水模拟)

39 篇文章 0 订阅
LightOJ - 1389
Time Limit: 2000MSMemory Limit: 32768KB64bit IO Format: %lld & %llu

Submit Status

Description

Taso owns a very long field. He plans to grow different types of crops in the upcoming growing season. The area, however, is full of crows and Taso fears that they might feed on most of the crops. For this reason, he has decided to place some scarecrows at different locations of the field.

The field can be modeled as a 1 x N grid. Some parts of the field are infertile and that means you cannot grow any crops on them. A scarecrow, when placed on a spot, covers the cell to its immediate left and right along with the cell it is on.

Given the description of the field, what is the minimum number of scarecrows that needs to be placed so that all the useful section of the field is covered? Useful section refers to cells where crops can be grown.

Input

Input starts with an integer T (≤ 50), denoting the number of test cases.

Each case starts with a line containing an integer N (0 < N < 100). The next line contains N characters that describe the field. A dot (.) indicates a crop-growing spot and a hash (#) indicates an infertile region.

Output

For each case, print the case number and the number of scarecrows that need to be placed.

Sample Input

3

3

.#.

11

...##....##

2

##

Sample Output

Case 1: 1

Case 2: 3

Case 3: 0

Source

Problem Setter: Sohel Hafiz
Special Thanks: Jane Alam Jan
//题意:输入一个n,再输入一行n个字符
字符.表示可以种话的地方,#表示不能种花的地方,现在为了防止花被乌鸦吃了,要用稻草人来吓唬乌鸦,一个稻草人可以看管与它相邻的左右两个种子,现在问最少需要几个稻草人。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
char s[110];
int main()
{
	int t,T=1,n,i,j,l;
	scanf("%d",&t);
	while(t--)
	{
		int cnt=0;
		scanf("%d",&n);
		scanf("%s",s);
		i=0;
		while(i<n)
		{
			if(s[i]=='.')
				cnt++,i+=3;
			else
				i++;
		}
		printf("Case %d: %d\n",T++,cnt);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值