http://www.bnuoj.com/bnuoj/problem_show.php?pid=20834

【题意】:
 每次减少一半的空格,问经过多少次操作能得到每个单词之间的空格为1,输入字符串大小小于等于1MB

【题解】:
1、如果单词之间最大的空格数为2的n次方,那么输出2
2、否则输出n+1
注意字符串大小1MB,这里用C++中string进行处理
【code】:

 #include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <math.h> using namespace std; int main()
{
string str;
while(getline(cin,str)) //用string整行读入
{
int i,cnt=,maks=-;
for(i=;i<str.size();i++)
{
if(str[i]!=' ')
{
if(maks<cnt)
{
maks=cnt; //记录最大空格数
}
cnt=;
}
else
{
cnt++;
}
}
double ans = log(maks)/log();
int cmp = (int)(ans);
if(fabs(ans-cmp)<1e-) //如果刚好是2的n次方
{
cout<<cmp<<endl;
}
else //否则+1
{
cout<<cmp+<<endl;
}
}
return ;
}
 #include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <math.h> using namespace std; int main()
{
string str;
while(getline(cin,str)) //用string整行读入
{
int i,cnt=,maks=-;
for(i=;i<str.size();i++)
{
if(str[i]!=' ')
{
if(maks<cnt)
{
maks=cnt; //记录最大空格数
}
cnt=;
}
else
{
cnt++;
}
}
double ans = log(maks)/log();
int cmp = (int)(ans);
if(fabs(ans-cmp)<1e-) //如果刚好是2的n次方
{
cout<<cmp<<endl;
}
else //否则+1
{
cout<<cmp+<<endl;
}
}
return ;
}

bnuoj 20834 Excessive Space Remover(水水)的更多相关文章

  1. Effective Java 75 Consider using a custom serialized form

    Principle Do not accept the default serialized form without first considering whether it is appropri ...

  2. 线性时间常数空间找到数组中数目超过n/5的所有元素

    问题描述: Design an algorithm that, given a list of n elements in an array, finds all the elements that ...

  3. Devexpress VCL Build v2013 vol 13.2.2 发布

    devexpress 2013 的第二个大版本出来了,一如既往, 基本上还是一个大补丁包.各位看官,自己看. What's New in 13.2.2 (VCL Product Line)   New ...

  4. codeforce1046 Bubble Cup 11 - Finals 题解

    比赛的时候开G开了3h结果rose说一句那唯一一个AC的是羊的心态就崩了.. 这套题感觉质量挺好然后就back了下 A: AI robots 有三个限制条件:相互能够看见和智商的差.使用主席树,可以维 ...

  5. python之terminaltables

    from terminaltables import AsciiTable, DoubleTable, SingleTable from colorclass import Color, Window ...

  6. java head space/ java.lang.OutOfMemoryError: Java heap space内存溢出

    上一篇JMX/JConsole调试本地还可以在centos6.5 服务器上进行监控有个问题端口只开放22那么设置的9998端口 你怎么都连不上怎么监控?(如果大神知道还望指点,个人见解) 线上项目出现 ...

  7. Eclipse中启动tomcat报错java.lang.OutOfMemoryError: PermGen space的解决方法

    有的项目引用了太多的jar包,或者反射生成了太多的类,异或有太多的常量池,就有可能会报java.lang.OutOfMemoryError: PermGen space的错误, 我们知道可以通过jvm ...

  8. myeclipse 内存不够用报错PermGen space 和 An internal error has occurred.

    最近项目中又增加了新的模块,项目的代码又多了不少.运行的时候总是报如下错误 Exception in thread "http-apr-80-exec-6" java.lang.O ...

  9. java.lang.OutOfMemoryError: PermGen space及其解决方法

    PermGen space的全称是Permanent Generation space,是指内存的永久保存区域OutOfMemoryError: PermGen space从表面上看就是内存益出,解决 ...

随机推荐

  1. Git CMD - push: Update remote refs along with associated objects

    命令格式 git push [--all | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [--receive-pac ...

  2. HDOJ2020绝对值排序

    绝对值排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  3. android组件间共享数据的常用方法

    使用Intent在激活组件的时候携带数据,以进行数据的传递 使用广播进行组件间数据的伟递 使用外部存储(sharedPreference,文件,数据库,网络)进行组件间数据共享 使用Static静态成 ...

  4. 和阿文一起学H5——如何搜到超酷的GIF素材

    方法一: 1.条件搜索法 关键词 + gif 2.dribbble全球顶点设计师殿堂,里面有好多大师神作. https://dribbble.com/ 3.pinterest,号称灵感的春药的网站,收 ...

  5. ecshop调用文章显示上一篇下一篇

    首先调用文章中的上一篇和下一篇语法为:  代码如下 复制代码 上一篇:<a href="{$next_article.url}">{$next_article.titl ...

  6. 使用Emmet(前身Zen Coding)加速Web前端开发

    Emmet插件以前被称作为Zen Coding,是一个文本编辑器的插件,它可以帮助您快速编写HTML和CSS代码,从而加速Web前端开发.早在2009年,Sergey Chikuyonok写过一篇文章 ...

  7. 关于web上的图片格式问题,新的彩蛋

    我们耳熟能详的几种格式无外乎 png-8,png-24,jpeg,gif,svg. 但是上面的那些都不是能够另人惊喜的答案.关于新技术的是Webp,Apng.(是否有关注新技术,新鲜事物) 1)Web ...

  8. javascript笔记—— 构造函数

    出处:http://www.cnblogs.com/RicCC/archive/2008/02/15/JavaScript-Object-Model-Execution-Model.html 数据类型 ...

  9. jquery-ui 中treegird 逐步加载

    官方网站上没有ajax逐步加载的例子,自己研究了下 js代码 $("#bomStructureTable").treegrid({ url : "systemcontro ...

  10. 第一节 Hibernate 基本配置

    1 新建maven工程 1)打开eclipse,依次点击File---->New---->Maven Project. 2)选择org.apache.maven.archetypes ma ...