题目:http://codeforces.com/contest/570/problem/C

题意:给你一个字符串,由‘.’和小写字母组成。把两个相邻的‘.’替换成一个‘.’,算一次变换。现在给你一些个操作,操作内容是把某个位置的字符变成给定的 字符,求出每次操作后,需要多少次

变换才能把原串所有相邻的‘.’变成一个‘.’。注意,每次操作是累加的,即一次操作就会把原串替换一个字符。

分析:先求出原串的变换次数sum,然后每次询问的时候,直接看他的两边是否是".",如果是"."num++。因为是累加的,所以在每次循环过后需要更新字符串以及sum。

 #include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define pfi(n) printf("%d\n", n)
#define N 100010
string s;
vector<int> p[N];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
cin>>s;
int flag = ,t,sum = ;
repu(i,,n)
{
if(s[i] == '.' && !flag)
{
flag = ;
t = i;
}
else if(flag && s[i] != '.')
{
sum += (i-t-);
flag = ;
}
}
if(flag)
sum += (n-t-);
//printf("%d\n",sum);
char p;
int num = sum,a;
repu(i,,m)
{
scanf("%d %c",&a,&p);
if(p != '.')
{
if(s[a-] != '.')
num = sum;
else
{
if(a- >= && s[a-] == '.')
num--;
if(s[a] == '.' && a < n)
num--;
}
s[a-] = p;
sum = num;
}
else
{
if(s[a-] == '.')
num = sum;
else
{
if(a- >= && s[a-] == '.')
num++;
if(s[a] == '.' && a < n)
num++;
}
s[a-] = p;
sum = num;
}
printf("%d\n",num);
}
}
return ;
}

Codeforces 570C 贪心的更多相关文章

  1. CodeForces - 893D 贪心

    http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...

  2. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  3. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心

    Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...

  4. CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作

    题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...

  5. C - Ordering Pizza CodeForces - 867C 贪心 经典

    C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...

  6. Codeforces 732e [贪心][stl乱搞]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...

  7. Codeforces 721D [贪心]

    /* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给一列数a,可以进行k次操作,每次操作可以选取任意一个数加x或者减x,x是固定的数.求如何才能使得这个数列所有数乘积最小. 思路: 贪心...讨 ...

  8. CodeForces - 424B (贪心算法)

    Megacity Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Sta ...

  9. CodeForces 489C (贪心) Given Length and Sum of Digits...

    题意: 找出m位且各个数位数字之和为s的最大和最小整数,不包括前导0(比如说003是非法的),但0是可以的. 分析: 这题是用贪心来做的,同样是m位数,前面的数字越大这个数就越大. 所以写一个can( ...

随机推荐

  1. SQL Server附加数据库问题

    SQL Server附加数据库时,遇到如下问题:“如果升级全文目录,请单加“添加目录”,然后找到它并选择它.基于全文升级选项,全文索引将为“已导入”.” 解决方法: 选择数据库文件所在目录,右键-&g ...

  2. 189. Rotate Array

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  3. Getting Started with JD Edwards EnterpriseOne Interoperability

      Overview Every enterprise holds a forest of branched system spread across a number of business uni ...

  4. [原创]WPF应用MediaPlayer播放声音断续、不全解决方案

    1.检查扬声器和驱动程序. 测试方法:首先,应用Windows Media Player播放器播放,看是否有问题,如果有问题,基本断定是驱动程序问题.其次,点击扬声器,选择测试,查看扬声器是否好用,如 ...

  5. c# 获取 本周、本月、本季度、本年 的开始时间或结束时间

    #region 获取 本周.本月.本季度.本年 的开始时间或结束时间 /// <summary> /// 获取结束时间 /// </summary> /// <param ...

  6. hibernate入门实例

    1. 环境配置 1.1 hiberante环境配置 hibernate可实现面向对象的数据存储.hibernate的官网:http://hibernate.org/ 官网上选择hibernate OR ...

  7. Dependency Scope

    Dependency Scope <dependency>中还引入了<scope>,它主要管理依赖的部署.目前<scope>可以使用5个值: * compile,缺 ...

  8. 使用Support Vector Machine

    使用svm(Support Vector Machine)中要获得好的分类器,最重要的是要选对kernel. 常见的svm kernel包括linear kernel, Gaussian kernel ...

  9. Mallet 使用说明

    Mallet:自然语言处理工具包 发表于128 天前 ⁄ 技术, 科研 ⁄ 评论数 6 ⁄ 被围观 1006 Views+ MALLET是基于java的自然语言处理工具箱,包括分档得分类.句类.主题模 ...

  10. Bootstrap <基础五>表格

    Bootstrap 提供了一个清晰的创建表格的布局.下表列出了 Bootstrap 支持的一些表格元素: 标签 描述 <table> 为表格添加基础样式. <thead> 表格 ...