Power Strings 分类: POJ 串 2015-07-31 19:05 8人阅读 评论(0) 收藏
Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
Practice
POJ 2406
Appoint description:
Description
Given two strings a and b we define a*b to be their concatenation. For example, if a = “abc” and b = “def” then a*b = “abcdef”. If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = “” (the empty string) and a^(n+1) = a*(a^n).
Input
Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.
Output
For each s you should print the largest n such that s = a^n for some string a.
Sample Input
abcd
aaaa
ababab
.
Sample Output
1
4
3
Hint
This problem has huge input, use scanf instead of cin to avoid time limit exceed.
开始的时候数组开了,orz
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <list>
#include <algorithm>
#define RR freopen("output.txt","r",stdoin)
#define WW freopen("input.txt","w",stdout)
typedef long long LL;
using namespace std;
const int MAX = 1000010;
char s[MAX];
int next[MAX];
int len;
void Build_next()
{
int i=0,j=-1;
len=strlen(s);
next[0]=-1;
while(i<len)
{
if(j==-1||s[i]==s[j])
{
i++;
j++;
next[i]=j;
}
else
{
j=next[j];
}
}
}
int main()
{
while(scanf("%s",s)&&strcmp(s,"."))
{
Build_next();
int ans=len-next[len];
if(len%ans)
{
printf("1\n");
}
else
{
printf("%d\n",len/ans);
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
Power Strings 分类: POJ 串 2015-07-31 19:05 8人阅读 评论(0) 收藏的更多相关文章
- android开发之this.finish()的使用 分类: android 学习笔记 2015-07-18 19:05 30人阅读 评论(0) 收藏
在一个Activity用完之后应该将之finish掉,但是,之前在学校里自己摸索着开发时并没有太注意这个问题,因为activity无论是否finish掉对功能的影响貌似都不是那么明显(这是读书时候的观 ...
- OC基础:类的扩展.协议 分类: ios学习 OC 2015-06-22 19:22 34人阅读 评论(0) 收藏
//再设计一个类的时候,有些方法需要对外公开(接口),有些仅供内部使用. 类的扩展:为类添加新的特征(属性)或者方法 对已知类: 1.直接添加 2.继承(在其子类中添加实例变量和方法) 3.使用ext ...
- UI基础:事件.响应链 分类: iOS学习-UI 2015-07-03 19:51 1人阅读 评论(0) 收藏
UIEvent:事件,是由硬件捕捉的一个代表用户操作操作设备的对象. 事件分三类:触摸事件.晃动事件.远程控制事件. 触摸事件:用户通过触摸设备屏幕操作对象,.输入数据.支持多点触摸,包含1个到多个触 ...
- UI基础:UILabel.UIFont 分类: iOS学习-UI 2015-07-01 19:38 107人阅读 评论(0) 收藏
UILabel:标签 继承自UIView ,在UIView基础上扩充了显示文本的功能.(文本框) UILabel的使用步骤 1.创建控件 UILabel *aLabel=[[UILabel alloc ...
- OC基础:Date 分类: ios学习 OC 2015-06-22 19:16 158人阅读 评论(0) 收藏
NSDate 日期类,继承自NSObject,代表一个时间点 NSDate *date=[NSDate date]; NSLog(@"%@",date); //格林尼治时间, ...
- OC基础:block.字面量 分类: ios学习 OC 2015-06-22 19:08 155人阅读 评论(0) 收藏
block 块语法,可以用block去保存一段代码,或者封装一段代码. block 实际是由c语言实现的,执行效率很高. block 实际借鉴了函数指针的语法. block,在多线程.异步任务,集合遍 ...
- OC基础:继承.初始化方法,便利构造器 分类: ios学习 OC 2015-06-16 19:27 84人阅读 评论(0) 收藏
继承: 1.单向继承,一个类只能有一个父类,一个父类可以有多个子类. 2.单向继承,基类(根类)是OSObject 3.子类可以继承父类的属性和方法 当父类的方法不满足子类的需求时,子类可以重写父类的 ...
- OC基础:getter和setter,@public @protected @private 分类: ios学习 OC 2015-06-15 19:23 22人阅读 评论(0) 收藏
@public 1.公开的,公共的,可以在类的内部和外部访问. 2.类的内部:实例变量名 3.类的外部:对象->实例变量名 @protected 1.受保护的,只能在本类和子类中可以访问 2.类 ...
- Matlab调用C程序 分类: Matlab c/c++ 2015-01-06 19:18 464人阅读 评论(0) 收藏
Matlab是矩阵语言,如果运算可以用矩阵实现,其运算速度非常快.但若运算中涉及到大量循环,Matlab的速度令人难以忍受的.当必须使用for循环且找不到对应的矩阵运算来等效时,可以将耗时长的函数用C ...
随机推荐
- UEditor和CKEditor配置上传图片,视频,附件
UEditor: http://blog.sina.com.cn/s/blog_8bb128230102v12x.html CKEditor:http://blog.sina.com.cn/s/blo ...
- Leetcode: Convert a Number to Hexadecimal
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two's compl ...
- 通达信:显示K线图日期
INFO_A:=STRCAT('INFO_A=', STRCAT(CON2STR(REF(MONTH, REF_BAR_A), 0), STRCAT('-', STRCAT(CON2STR(REF(D ...
- HDU 4064 Carcassonne(插头DP)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4064 Problem Description Carcassonne is a tile-based ...
- URAL 1001 Reverse Root(水题?)
The problem is so easy, that the authors were lazy to write a statement for it! Input The input stre ...
- 侧菜单栏的实现SlidingPaneLayout
SlidingPaneLayout分为两部分,上面的 左划出部分和没划出的时候 <?xml version="1.0" encoding="utf-8"? ...
- JSon_零基础_003_将Map集合对象转换为JSon格式的对象字符串,返回给界面
将Map集合对象转换为JSon格式的对象字符串,返回给界面 需导入的jar包: 编写servlet: package com.west.webcourse.servlet; import java.i ...
- windows 下双网卡在不同网络切换设置
首先你的机器需要有两块网卡,分别接到两台交换机上, ine rnet地址:192.168.1.8,子网掩码:255.255.255.0,网关:192.168.1.1 内部网地址:172. ...
- SQL Server2008 错误源:.net SqlClient data provider的解决方法
今天下午直接在SQL Server 2008的Microsoft SQL Server Management Studio 中修改一张表中某个字段, 不管是删除字符还是添加都提示下面的错误. 网上很多 ...
- NOIP199904求Cantor表
求Cantor表 题目描述 Description 现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的.他是用下面这一张表来证明这一命题的: 1/1 1/2 1/3 1/4 1/5 ...