2016年武汉科技大学邀请赛网络赛 G题

来源:互联网 发布:南木梁知 编辑:程序博客网 时间:2024/04/30 13:27

Eliminating Fun

Time Limit: 10 Sec  Memory Limit: 128 MB   64bit IO Format: %lld
Submitted: 61  Accepted: 9
[Submit][Status][Web Board]

Description

Q is busy hunting for jobs, resulting in that he can't solve algorithmic problem quicklyBu Recenly ZZ have a easy problem, Xiao Q wants to help, But Xiao Q can’t solve it too, so can you solve it!

Give you a string, if you find adjacent characters are both '.', then you could cut one. You will have N operations:

X P -------- Replace the Xth character with P

How many dots do you have to cut so that there are no adjacent dots?

Input

Multiply test cases, terminate with EOF. The descriptions of the test cases follow:

Each testcase contains three parts, the first line contains two intergers L, N, the second line contains a string, the follow N lines contain X P in each line;

Note that the former operations will change our string. See the example for more information.

1 <= T <= 100, 1 <= L <= 100000, 1 <= N <= 100000, 1 <= X <= L .

Output

For each operation, output the answer in one line.

Sample Input

16 3B...DDDTen...ENT3 B10 .16 .

Sample Output

233

HINT

Huge input, recommend scanf rather than cin.


题目意思:给出一组字符串,然后给出进行的操作,这里每一步的操作都是建立在上一层操作后的结果上的,也就是说你上一层弄错了后面就全错。问操作完了之后最少需要去掉几个点使得字符串里面没有连续的两个点。


题解:对于每个操作,仅判断是增加了连续点区间还是合并了连续点区间即可,然后最小操作数是点数减区间数。

为什么这么做呢,比如X个点Y个区间,X-Y,本事就一个点的区间消失了,剩下的就是多余一个点的区间,这个情况下剩下的每个点都需要消去,因为最后每个点都代表一个区间明所以X-Y可以得到答案。

(这个做题的时候真的没想到这么做)

0 0