String reduction
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1360   Accepted: 447

Description

There is a string of characters 'a' and 'b' with the length of no more than 255 characters. You can perform the substring reduction on the initial string in the following way: a substring "a*a" or "b*b" (where * (asterisk) denotes any character) can be reduces to a substring "*".

The task is to achieve a string of minimal possible length after several substring reductions.

Input

The input contains the initial string.

Output

The output contains a single line with the minimal possible length.

Sample Input

aab

Sample Output

3

Source

Northeastern Europe 2001, Western Subregion
题意:在一个串中形如a*a 或b*b可以变换为a或b,问变换之后最短长度。

由于a*a, b*b之类的字符可以匹配任意字符,那么我们只要从前

向后扫描,如果有相隔的两个字符相同,由于这三个字符能够匹配a,b任意字符,那么我们就可以让这种匹配一直进行

下去,从而将字符串不断的reduction ,只要注意字符串长度的奇偶性就可以了,如此我们可以得到一个很简单的方法

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue> using namespace std; #define N 1100
#define INF 0xfffffff
#define eps 1e-8 int main()
{
char str[N]; scanf("%s", str);
int ans, len;
len = ans = strlen(str); for(int i = ; i + < len; i++)
{
if(str[i] == str[i+])
{
if(len % )
ans = ;
else
ans = ;
}
}
printf("%d\n", ans);
return ;
}

String reduction (poj 3401的更多相关文章

  1. 雷达装置 (POJ 1328/ codevs 2625)题解

    [问题描述] 假定海岸线是一条无限延伸的直线,陆地在海岸线的一边,大海在另一侧.海中有许多岛屿,每一个小岛我们可以认为是一个点.现在要在海岸线上安装雷达,雷达的覆盖范围是d,也就是说大海中一个小岛能被 ...

  2. C++ Primer 学习笔记_32_STL实践与分析(6) --再谈string类型(下)

    STL实践与分析 --再谈string类型(下) 四.string类型的查找操作 string类型提供了6种查找函数,每种函数以不同形式的find命名.这些操作所有返回string::size_typ ...

  3. 通过Java字节码发现有趣的内幕之String篇(上)(转)

    原文出处: jaffa 很多时候我们在编写Java代码时,判断和猜测代码问题时主要是通过运行结果来得到答案,本博文主要是想通过Java字节码的方式来进一步求证我们已知的东西.这里没有对Java字节码知 ...

  4. Lua 中的string库(字符串函数库)总结

    (字符串函数库)总结 投稿:junjie 字体:[增加 减小] 类型:转载 时间:2014-11-20我要评论 这篇文章主要介绍了Lua中的string库(字符串函数库)总结,本文讲解了string库 ...

  5. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  6. 跟着刚哥梳理java知识点——深入理解String类(九)

    一.String类 想要了解一个类,最好的办法就是看这个类的实现源代码,来看一下String类的源码: public final class String implements java.io.Ser ...

  7. Leetcode#557. Reverse Words in a String III(反转字符串中的单词 III)

    题目描述 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" 输 ...

  8. 1050 String Subtraction (20 分)

    1050 String Subtraction (20 分) Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the ...

  9. Mediocre String Problem (2018南京M,回文+LCP 3×3=9种做法 %%%千年好题 感谢"Grunt"大佬的细心讲解)

    layout: post title: Mediocre String Problem (2018南京M,回文+LCP 3×3=9种做法 %%%千年好题 感谢"Grunt"大佬的细 ...

随机推荐

  1. Iview 启动报错 TypeError [ERR_INVALID_CALLBACK]: Callback must be a function

    解决 fs.write(fd, buf, 0, buf.length, 0, function(err, written, buffer) {}); 替换为 fs.write(fd, buf, 0, ...

  2. uve (mui/light7)写APP的使用心得(大坑);

    话说mui这个框架的UI确实挺好看的(个人觉得)所以项目使用了他,结果里面的坑太TM多,不得不说MUI做东西太不用心了,社区不活跃,提问都没人管!; mui第一个坑: 日期选择器默认值无效:使用代码跟 ...

  3. IMAP协议学习笔记(一)

    IMAP IMAP(Internet Mail Access Protocol,Internet邮件访问协议)以前称作交互邮件访问协议(Interactive Mail Access Protocol ...

  4. zip loader

    GS.ZipAssetLoader = function(audioContext) { this.audioContext = audioContext, this.objLoader = new ...

  5. 2018-5-5-UWP-和-WPF-对比

    title author date CreateTime categories UWP 和 WPF 对比 lindexi 2018-05-05 17:23:33 +0800 2018-04-16 20 ...

  6. 如何在Linux下手动编译安装gcc

    如果可以通过apt来安装的话,尽量不要手工编译了,手工编译是最后的选择.用apt安装,只需要输入一条命令: sudo apt-get install gcc 手工编译的话,gcc和其他软件包存在如下的 ...

  7. 用C#实现获取文件夹大小的源代码

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  8. JS 控制子页面刷新父页面

    iframe里面的子页,用parent.location.href = parent.location.reload();如果是window.open 打开就用opener.location.relo ...

  9. V7双雄-基于Virtex7XC7VX690T的高性能计算板卡解决方案

    北京太速V7双雄-基于Virtex7XC7VX690T的高性能计算板卡

  10. 卷积神经网络 CNN 系列模型阐述

    http://www.sohu.com/a/134347664_642762 Lenet,1986年 https://github.com/BVLC/caffe/blob/master/example ...