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. hdu 4614 线段树

    思路:当k为1的时候,用二分法查询包含有f个空瓶的上界r,然后更新会方便很多,直接更新区间(a,r)了. #include<iostream> #include<cstdio> ...

  2. 为什么Java byte 类型的取值范围是-128~127 (转)

    概念:负数的补码是该 数 绝 对 值 的 原 码 按 位 取 反 ,然 后 对 整个数 加 1 步骤: 1.确定byte是1个字节,也就是8位 2.最大的应该是0111 1111,因为第一位是符号位, ...

  3. Next Power of 2

    Next Power of 2 Write a function that, for a given no n, finds a number p which is greater than or e ...

  4. form提交数据中文乱码问题总结

    一:form在前台以post方式提交数据: 浏览器将数据(假设为“中国”)发送给服务器的时候,将数据变成0101的二进制数据(假设为98 99)时必然要查码表,浏览器以哪个码表打开网页,浏览器就以哪个 ...

  5. SQL之存储过程,仿数组

    create procedure update_ERPTreeList(@s1 varchar(),@s2 varchar()) As Begin declare @ss1 varchar(),@ss ...

  6. Bresenham算法画填充圆及SDL代码实现

    画圆是计算机图形操作中一个非常重要的需求.普通的画圆算法需要大量的浮点数参与运算,而众所周知,浮点数的运算速度远低于整形数.而最终屏幕上影射的像素的坐标均为整形,不可能是连续的线,所以浮点数运算其实纯 ...

  7. spring3.2以后的cglib的jar包问题

    关于cglib的jar包官方的文档上有这么一段话 Note For this dynamic subclassing to work, the class that the Spring contai ...

  8. 按按钮调用PHP function函数

    首先,请大家看一段HTML代码: <html> <head> </head> <body> <input type=button on_click ...

  9. 一次GC问题定位

    同事有段代码执行时间过长,需要进行优化, Hashmultimap<Int,Bean> map = ...; for (400w*96) { // 计算过程 Bean = doComput ...

  10. DB Cache Reloaded Fix缓存不能被激活解决方法

    1.创建wp-content/plugins/db-cache-reloaded-fix/cache目录. 2.将cache权限改为777. 3.拷贝wp-content/plugins/db-cac ...