bnuoj 20834 Excessive Space Remover(水水)
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(水水)的更多相关文章
- Effective Java 75 Consider using a custom serialized form
Principle Do not accept the default serialized form without first considering whether it is appropri ...
- 线性时间常数空间找到数组中数目超过n/5的所有元素
问题描述: Design an algorithm that, given a list of n elements in an array, finds all the elements that ...
- Devexpress VCL Build v2013 vol 13.2.2 发布
devexpress 2013 的第二个大版本出来了,一如既往, 基本上还是一个大补丁包.各位看官,自己看. What's New in 13.2.2 (VCL Product Line) New ...
- codeforce1046 Bubble Cup 11 - Finals 题解
比赛的时候开G开了3h结果rose说一句那唯一一个AC的是羊的心态就崩了.. 这套题感觉质量挺好然后就back了下 A: AI robots 有三个限制条件:相互能够看见和智商的差.使用主席树,可以维 ...
- python之terminaltables
from terminaltables import AsciiTable, DoubleTable, SingleTable from colorclass import Color, Window ...
- java head space/ java.lang.OutOfMemoryError: Java heap space内存溢出
上一篇JMX/JConsole调试本地还可以在centos6.5 服务器上进行监控有个问题端口只开放22那么设置的9998端口 你怎么都连不上怎么监控?(如果大神知道还望指点,个人见解) 线上项目出现 ...
- Eclipse中启动tomcat报错java.lang.OutOfMemoryError: PermGen space的解决方法
有的项目引用了太多的jar包,或者反射生成了太多的类,异或有太多的常量池,就有可能会报java.lang.OutOfMemoryError: PermGen space的错误, 我们知道可以通过jvm ...
- myeclipse 内存不够用报错PermGen space 和 An internal error has occurred.
最近项目中又增加了新的模块,项目的代码又多了不少.运行的时候总是报如下错误 Exception in thread "http-apr-80-exec-6" java.lang.O ...
- java.lang.OutOfMemoryError: PermGen space及其解决方法
PermGen space的全称是Permanent Generation space,是指内存的永久保存区域OutOfMemoryError: PermGen space从表面上看就是内存益出,解决 ...
随机推荐
- 会话跟踪技术——cookie
一.会话控制 为了使得网站可以跟踪客户端与服务器之间的交互,保存和记忆每个用户的身份和信息,我们需要一种强有力的解决方案,这样就产生了会话控制. HTTP是一个无状态的协议,此协议无法来维护两个事务之 ...
- Java Concurrency - Callable & Future
One of the advantages of the Executor framework is that you can run concurrent tasks that return a r ...
- Redis 命令 - Transactions
DISCARD Discard all commands issued after MULTI 127.0.0.1:6379> MGET bank:A:account bank:B:accoun ...
- HDOJ2026首字母变大写
首字母变大写 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- Android代码内存优化建议-OnTrimMemory优化
原文 http://androidperformance.com/2015/07/20/Android代码内存优化建议-OnTrimMemory优化/ OnTrimMemory 回调是 Androi ...
- C#中的 ref 传进出的到底是什么 解惑篇
今天在浏览博文时,看到这篇文章:C#中的ref 传进出的到底是什么 ? 在传对象时使用ref的疑问 另附言: 本文写于早上,就在想发布的那瞬间,靠,公司断网了,原来修改的部分丢失了. 网一断就是一天了 ...
- Servlet之创建与配置
上篇已将介绍完了,下面来实践操作走一个: 首先在名为"com.caiduping"的包中创一个MyFilter的对象: 1 package com.caiduping; 2 3 i ...
- 设置win7任务栏显示标题,而不显示缩略图
win7系统的任务栏可以显示桌面缩略图,这是非常好的一个功能,但是有时候我们希望只显示标题,如下所示 怎样设置呢?只要在桌面上的计算机图标上面“右键”,选择“属性”,在弹出的窗口选择“高级系统设置”, ...
- 【转载】应广大群众的要求,今天开始连载《超容易的Linux系统管理入门书》一书
学习Linux容易嘛?我说超容易,你肯定不信.那学习Linux最好的学习方法是什么,就是脑子里面一直提问题,不停的提,时时刻刻提,如果你没有问题,那再容易的学习书你也看不懂. <超容易的Linu ...
- UVaLive 7361(矩阵快速幂)
题意:矩阵快速幂求斐波那契数列. 分析: