CodeForces 909D Colorful Points
题解:
暴力,模拟。
把字符串压缩一下,相同的处理成一位,记录下个数,然后暴力模拟即可。
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e6 + 10;
char s[maxn]; struct X {
char id;
int num;
}p[maxn], q[maxn];
int sz; void work() {
for(int i = 0; i <= sz; i ++) {
if(i == 0 || i == sz) {
p[i].num --;
} else {
p[i].num --;
p[i].num --;
}
}
int cnt = 0;
for(int i = 0; i <= sz; i ++) {
if(p[i].num <= 0) continue;
q[cnt ++] = p[i];
}
sz = 0;
p[0] = q[0];
for(int i = 1; i < cnt; i ++) {
if(q[i].id == p[sz].id) p[sz].num += q[i].num;
else {
sz ++;
p[sz] = q[i];
}
}
} int main() {
scanf("%s", s);
p[sz].id = s[0];
p[sz].num = 1;
for(int i = 1; s[i]; i ++) {
if(s[i] == p[sz].id) p[sz].num ++;
else {
sz ++;
p[sz].id = s[i];
p[sz].num = 1;
}
}
int ans = 0;
while(1) {
if(sz == 0) break;
work();
ans ++;
}
printf("%d\n", ans);
return 0;
}
CodeForces 909D Colorful Points的更多相关文章
- Codeforces Round #455 (Div. 2) 909D. Colorful Points
题 OvO http://codeforces.com/contest/909/problem/D CF 455 div2 D CF 909D 解 算出模拟的复杂度之后就是一个很水的模拟题 把字符串按 ...
- Codeforces 909 D. Colorful Points (模拟)
题目链接: Colorful Points 题意: 给出一段字符串(长度最大为1e6),每次操作可以删除字符串中所有相邻字符与其不同的字符.例如:aabcaa 删除一次就变成了aa,就无法再删除了.题 ...
- codeforces 19D D. Points 树套树
D. Points Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/19/problem/D De ...
- codeforces B.Fixed Points
link:http://codeforces.com/contest/347/problem/B 很简单,最多只能交换一次,也就是说,最多会增加两个.可能会增加一个.也可能一个也不增加(此时都是fix ...
- codeforces 577E E. Points on Plane(构造+分块)
题目链接: E. Points on Plane time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- codeforces B. Fixed Points 解题报告
题目链接:http://codeforces.com/problemset/problem/347/B 题目意思:给出一个包含n个数的排列a,在排列a中最多只能作一次交换,使得ai = i 这样的匹配 ...
- Codeforces909D Colorful Points(缩点)
http://codeforces.com/problemset/problem/909/D 直接模拟超时.要运用缩点的方法,把相同的一段缩成一点,记录有几个. 对于非首尾的缩点每次-2,首尾的-1. ...
- Codeforces - 1081C - Colorful Bricks - 简单dp - 组合数学
https://codeforces.com/problemset/problem/1081/C 这道题是不会的,我只会考虑 $k=0$ 和 $k=1$ 的情况. $k=0$ 就是全部同色, $k=1 ...
- codeforces 19 D. Points(线段树+set二分)
题目链接:http://codeforces.com/contest/19/problem/D 题意:给出3种操作:1)添加点(x,y),2)删除点(x,y),3)查询离(x,y)最近的右上方的点. ...
随机推荐
- Qt undefined reference to ***
错因:某个类声明了一个函数但是没有定义就直接使用.
- 更改gradle的java的class文件输出目录的结构
group 'com.thinkvenus.common'version '1.0-SNAPSHOT' apply plugin: 'java' sourceCompatibility = 1.8 r ...
- CALayer---iOS-Apple苹果官方文档翻译之CALayer
CHENYILONG Blog CALayer---iOS-Apple苹果官方文档翻译之CALayer CALayer /*技术博客http://www.cnblogs.com/ChenYilong/ ...
- 认识单点登录cas
么是单点登录?单点登录全称Single Sign On(以下简称SSO),是指在多系统应用群中登录一个系统,便可在其他所有系统中得到授权而无需再次登录,包括单点登录与单点注销两部分 1.登录 相比于单 ...
- HDU 1394 Minimum Inversion Number (树状数组)
题目链接 Problem Description The inversion number of a given number sequence a1, a2, ..., an is the numb ...
- 【译】第一篇 SQL Server代理概述
本篇文章是SQL Server代理系列的第一篇,详细内容请参考原文. SQL Server代理是SQL Server的作业调度和告警服务,如果使用得当,它可以大大简化DBA的工作量.SQL Serve ...
- three.js_ "Failed to execute 'texImage2D' on 'WebGLRenderingContext': tainted canvases may not be loded."
这个报错是请求图片跨域了. 1.当我们使用thee.js的时候肯定会碰到利用各种请求去向服务器请求贴图. 2.假设我们获取的是图片在服务器上的路径然后我们用 加载贴图到这里都是没有问题当我们在贴图加载 ...
- Tornado/Python 学习笔记(一)
1.源代码下载及安装:http://www.tornadoweb.org/en/stable/ 2.python中xmlrpc库官方文档:https://docs.python.org/3/libra ...
- Tensorflow中使用TFRecords高效读取数据--结合Attention-over-Attention Neural Network for Reading Comprehension
原文链接:https://arxiv.org/pdf/1607.04423.pdf 本片论文主要讲了Attention Model在完形填空类的阅读理解上的应用. 转载:https://blog.cs ...
- 五. Jmeter--HTTP Cookie Manager
1. 添加HTTP Cookie Manager 2.添加登录login http,request info 和 HTTP Header Manager 中的信息是从fiddler中拿的, 至于hea ...