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 3207 2-SAT问题
思路:将线段按开始点的升序排序,对线段尾节点进行判断,若存在交叉,那么这两条线段就不能同时在内或同时在外.这样将每条线段在内和在外看成两个状态i和i',i表示线段在内,i'表示线段在外.假使线段i和线 ...
- Linux下配置文件的位置
系统级的配置存放在 /etc 目录中.用户级的配置存放在用户的主目录 /home/user_login_name. SHELL 默认文件 /etc/bashrc – bash shell 的系统级默认 ...
- Javascript之spry菜单栏
我没有添加任何东西,这是Dreamweaver原汁原味用spry创建的菜单栏,以此来学习菜单导航,哈哈. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTM ...
- jQuery之手势密码
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- [转]SQL中使用WITH AS提高性能-使用公用表表达式(CTE)简化嵌套SQL
一.WITH AS的含义 WITH AS短语,也叫做子查询部分(subquery factoring),可以让你做很多事情,定义一个SQL片断,该SQL片断会被整个SQL语句所用到.有的时候, ...
- 个人实验记录之EIGRP基本配置
一.EIGRP的基本配置 1(1).进入接口配置IP R1(config)#inter s1/0 R1(config-if)#ip address 200.1.1.1 255.255.255.0 R1 ...
- XPath 初步讲解
2016-05-05 XPath是JavaScript 中节点查找手段,ie9以后的版本才支持w3c标准,其他浏览器基本支持.在e8之前的浏览器,通过基于 activeX的xml dom对象实现. 为 ...
- javascript 笔记——setTimeout的参数问题
setTimeout("xxx",500) 双引号中的作用域不捕捉局部变量,因此会报错误 如果你需要在双引号中可以在外部定义一个变量 var now; window.onload ...
- String 转Clob
把String转Clob java.sql.Clob c = new javax.sql.rowset.serial.SerialClob("abc".toCharArray())
- memset与NULL区别
memset与NULL区别 NULL与0 的区别 为什么强调一个malloc对应一个free 在一个结构体malloc,然后free,但是她的成员变量的malloc并没有free,还需要特别的free ...