Street Lamps
来源:互联网 发布:淘宝联名信用卡申请 编辑:程序博客网 时间:2024/05/17 23:33
C. Street Lamps
Bahosain is walking in a street of Nblocks. 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 Ncharacters, 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
.*.....*
思维题,想通了其实很简单的~~
把'*'能照到的地方换成'!',那么只有'.'的地方需要安装灯泡了,注意3个'.'需要一个灯泡,4个'.'就要两个才行了,所以计算的时候要加个2,再除以3。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){ int t,n; char a[105]; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); scanf("%d",&n); getchar();//这个一定要!!! for(int i=0; i<n; i++) scanf("%c",&a[i]); for(int i=0; i<n; i++) { if(a[i]=='*') { if(i==0) { if(a[i+1]=='.') a[i+1]='!'; } if(i==n-1) { if(a[i-1]=='.') a[i-1]='!'; } else { if(a[i-1]=='.') a[i-1]='!'; if(a[i+1]=='.') a[i+1]='!'; } } } int ans=0,sum=0; for(int i=0; i<n; i++) { if(a[i]=='.') sum++; else { ans+=(sum+2)/3; sum=0; } } ans+=(sum+2)/3; printf("%d\n",ans); } return 0;}
- Street Lamps
- Gym-100712C-Street Lamps
- Gym 100712C Street Lamps
- GYM 100712 C.Street Lamps(贪心)
- ACM Amman Collegiate Programming Contest C. Street Lamps
- lamps
- Street
- 2.2 lamps
- Party Lamps
- Party Lamps
- Party Lamps
- USACO lamps
- USACO LAMPS
- usaco lamps
- USACO 2.2 Party Lamps (lamps)
- USACO2.2.4 Party Lamps (lamps)
- USACO2.2.4 Party Lamps (lamps)
- Street Numbers
- 站在巨人的肩膀上,C++开源库大全
- Win7下完全卸载Oracle 11g的步骤
- Java并发包
- 《Motion Design for iOS》(三十)
- Bug-JNI: JNI DETECTED ERROR IN APPLICATION: JNI CallVoidMethodV called with pending exception 'java.
- Street Lamps
- Codeforces Round #360 (Div. 2) 前三题题解【简单模拟+思维+二分图判定二分染色】
- NSLocale的重要性和用法简介
- 正则化奇异值分解Regularized Singular Value Decomposition (RSVD)
- xlistview的导入文件2
- 基于ORA-12170 TNS 连接超时解决办法详解
- 快的打车架构实践
- 从Android代码中来记忆23种设计模式
- Eclipse中tomcat的lib里面的servlet-api和jsp-api