题目: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. 改变CSS世界纵横规则的writing-mode属性

    改变CSS世界纵横规则的writing-mode属性 这篇文章发布于 2016年04月27日,星期三,23:12,归类于 css相关. 阅读 8292 次, 今日 71 次 by zhangxinxu ...

  2. Windows Store App JavaScript 开发:WinJS库控件

    在介绍了如何使用标准的HTML控件以及WinJS库中提供的新控件之后,下面来着重介绍WinJS库中几种常用的控件. (1)ListView控件 在开发Windows应用商店应用时可以使用ListVie ...

  3. <button>标签与<input type="button">标签

    <script type="text/javascript" src="/jquery-1.11.3.min.js"></script> ...

  4. 【 2013 Multi-University Training Contest 7 】

    HDU 4666 Hyperspace 曼哈顿距离:|x1-x2|+|y1-y2|. 最远曼哈顿距离,枚举x1与x2的关系以及y1与y2的关系,取最大值就是答案. #include<cstdio ...

  5. 更新证书错误:No matching provisioning profiles found

    在Xcode中当你在更新了你得证书而再重新编译你的程序,真机调试会出现“Your build settings specify a provisioning profile with the UUID ...

  6. asp.net mvc 防止开放重定向

    /// <summary> /// 防止开发重定向,篡改returnurl /// </summary> /// <param name="request&qu ...

  7. windows8.1下javaweb环境搭建及基本配置(jdk+tomcat+eclipse)

    1.下载安装jdk在无空格的路径下,否则在linux下可能出问题.配置环境变量: a.新建系统变量——JAVA_HOME,值——D:\programming\java\jdk8 // win8下若建为 ...

  8. listview指定某item的点击效果

    需求:listview的某些item能够点击,需要点击效果,有些item不能点击,需要屏蔽点击效果. 实现: 1.layout: <ListView android:id="@+id/ ...

  9. curl方法post一个数组

    $r = $this->curl_post($url, $data);$list = json_decode($r,true);   function curl_post($url = '', ...

  10. web开发流程(传智播客-方立勋老师)

    1.搭建开发环境 1.1 导入项目所需的开发包 dom4j-1.6.1.jar jaxen-1.1-beta-6.jar commons-beanutils-1.8.0.jar commons-log ...