Codeforces 570C 贪心
题目: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 贪心的更多相关文章
- CodeForces - 893D 贪心
http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...
- 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 ...
- 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 ...
- 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 ...
- C - Ordering Pizza CodeForces - 867C 贪心 经典
C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...
- Codeforces 732e [贪心][stl乱搞]
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...
- Codeforces 721D [贪心]
/* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给一列数a,可以进行k次操作,每次操作可以选取任意一个数加x或者减x,x是固定的数.求如何才能使得这个数列所有数乘积最小. 思路: 贪心...讨 ...
- CodeForces - 424B (贪心算法)
Megacity Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
- CodeForces 489C (贪心) Given Length and Sum of Digits...
题意: 找出m位且各个数位数字之和为s的最大和最小整数,不包括前导0(比如说003是非法的),但0是可以的. 分析: 这题是用贪心来做的,同样是m位数,前面的数字越大这个数就越大. 所以写一个can( ...
随机推荐
- Powerdesigner SqlServer转Oracle(转)
参考文章,原文地址:http://blog.csdn.net/cicada688/article/details/7802881 问题1:sqlserver数据库直接转oracle.字段类型由sql ...
- web前端页面项目经验总结
项目时间:2016年4月5日--4月9日项目名称:阿七果子园web前端页面项目内容: 1.HTML5+CSS+JavaScript(banner+timer)+JQuery(small_bann ...
- PHP弱类型需要特别注意的问题
下面介绍的问题都已验证, 总结:字符数据比较==不比较类型,会将字符转数据,字符转数字(转换直到遇到一个非数字的字符.即使出现无法转换的字符串,intval()不会报错而是返回0).0e,0x开头的字 ...
- 无废话SharePoint入门教程一[SharePoint概述]
一.前言 听说SharePoint也有一段时间了,可一直处在门外.最近被调到SharePoint实施项目小组,就随着工作一起学习了一下实施与开发.但苦于网上SharePoint入门的东西实在太少,导致 ...
- asp.net链接数据库问题,设置收藏本站,设置主页
SQL Server 2008附加数据库失败:无法打开物理文件拒绝访问解决方法 无法打开物理文件 "E:\SQLDATA\EMSXDB.mdf".操作系统错误 5:"5( ...
- winform webbrowser flash显示
string flashSrc = "e:\\t.swf"; StringBuilder sb = new StringBuilder(); sb.Append("< ...
- MindManger学习技巧
ctrl+shift+f 字体颜色
- #define DELAY_ONE_MICROSECOND (-10) 时间是负数的原因
以下摘自DOOM的博文<内核同步对象> http://blog.csdn.net/lqk1985/article/details/2541867 “最后一个参数&timeout是一 ...
- WPS for Linux(ubuntu)字体配置(字体缺失解决办法)
启动WPS for Linux后,出现提示"系统缺失字体" . 出现提示的原因是因为WPS for Linux没有自带windows的字体,只要在Linux系统中加载字体即可. 具 ...
- 【译】Android 6.0 Changes (机翻加轻微人工校对)
Android 6.0 Changes In this document Runtime Permissions Doze and App Standby Apache HTTP Client Rem ...