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从表面上看就是内存益出,解决 ...
随机推荐
- poj 2057 树形dp 贪心
思路:设sum[i],le[i],back[i],worm[i]分别表示以i为根节点需要的完成步数,叶子节点数,失败回退步数,以及i是否有虫. #include<iostream> #in ...
- merge into update
如果要DML实现真正意义上的并发,在开始执行需要并发语句前,需要执行开启session并发 ALTER SESSION ENABLE PARALLEL DML; 在执行完语句后,需要执行关闭ses ...
- Java Concurrency - ScheduledThreadPoolExecutor
The Executor framework provides the ThreadPoolExecutor class to execute Callable and Runnable tasks ...
- SQL Server 错误行号
https://msdn.microsoft.com/zh-cn/library/ms178600.aspx 返回发生错误的行号,该错误导致运行 TRY…CATCH 构造的 CATCH 块. 语法 E ...
- spring读取prperties配置文件(1)
博客地址http://www.cnblogs.com/shizhongtao/p/3438431.html 属性文件命名是*.properties,在java中,用类java.util.Propert ...
- 百练_2945 拦截导弹(DP)
描述 某国为了防御敌国的导弹袭击,开发出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度.某天,雷达捕捉到敌国的导弹来袭 ...
- Java Calendar类简单用法
我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3832307.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...
- lex&yacc8--wehter use in C++
bintree.h:12:1: error: unknown type name ‘using’ using namespace std; ============== bintree.h:28:1: ...
- IOCP模型总结(转)
IOCP模型总结(转) IOCP(I/O Completion Port,I/O完成端口)是性能最好的一种I/O模型.它是应用程序使用线程池处理异步I/O请求的一种机制.在处理多个并发的异步I/O请求 ...
- 【转】给Winform的button等控件添加快捷键
ref: http://blog.sina.com.cn/s/blog_4cb9953f0100cy4z.html 第一种:Alt + *(按钮快捷键) 在大家给button.label.menuSt ...