Revolving Digits

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25512    Accepted Submission(s): 5585

Problem Description
One day Silence is interested in revolving the digits of a positive integer. In the revolving operation, he can put several last digits to the front of the integer. Of course, he can put all the digits to the front, so he will get the integer itself. For example, he can change 123 into 312, 231 and 123. Now he wanted to know how many different integers he can get that is less than the original integer, how many different integers he can get that is equal to the original integer and how many different integers he can get that is greater than the original integer. We will ensure that the original integer is positive and it has no leading zeros, but if we get an integer with some leading zeros by revolving the digits, we will regard the new integer as it has no leading zeros. For example, if the original integer is 104, we can get 410, 41 and 104.
 
Input
The first line of the input contains an integer T (1<=T<=50) which means the number of test cases. 
For each test cases, there is only one line that is the original integer N. we will ensure that N is an positive integer without leading zeros and N is less than 10^100000.
 
Output
For each test case, please output a line which is "Case X: L E G", X means the number of the test case. And L means the number of integers is less than N that we can get by revolving digits. E means the number of integers is equal to N. G means the number of integers is greater than N.
 
Sample Input
1
341
 
Sample Output
Case 1: 1 1 1
 
Source
 
Recommend
zhoujiaqi2010   |   We have carefully selected several similar problems for you:  4332 4335 4334 4336 4337 

如果比较两个字符串,就比较第一位不一样的,那我们就需要找出所有字符串和已知字符串的前缀公共部分。
在已知字符串后面载copy一份,然后做exkmp就行了。
需要注意的是,相同字符串只能出现一次,所以先求一遍循环节。
有一篇关于exkmp的ppt:http://wenku.baidu.com/view/79992a90bed5b9f3f80f1c16.html?from=search

#include<cstdio>
#include<cstring>
using namespace std;
const int N=2e5+;
int cas,_,Next[N];
char T[N];
void kmp(int l){
int i=,j=-;Next[i]=j;
while(i<l){
if(j==-||T[i]==T[j]) Next[++i]=++j;
else j=Next[j];
}
}
void get_next(int Tlen){
int a=;
Next[]=Tlen;
while(a<Tlen-&&T[a]==T[a+]) a++;
Next[]=a;a=;
for(int k=;k<Tlen;k++){
int p=a+Next[a]-,L=Next[k-a];
if(k+L->=p){
int j=(p-k+>)?p-k+:;
while(k+j<Tlen&&T[k+j]==T[j]) j++;
Next[k]=j;a=k;
}
else Next[k]=L;
}
}
int main(){
for(scanf("%d",&_),cas=;cas<=_;cas++){
scanf("%s",T);
int len=strlen(T);
kmp(len);
int k=len-Next[len],tt;
if(len%k==) tt=len/k;
else tt=;
for(int i=;i<len;i++) T[len+i]=T[i];
get_next(len*);
int num1=,num2=,num3=;
for(int i=;i<len;i++){
if(Next[i]>=len) num2++;
else if(T[Next[i]]>T[i+Next[i]]) num1++;
else if(T[Next[i]]<T[i+Next[i]]) num3++;
}
printf("Case %d: %d %d %d\n",cas,num1/tt,num2/tt,num3/tt);
}
return ;
}

Revolving Digits[EXKMP]的更多相关文章

  1. Hdu 4333 Revolving Digits(Exkmp)

    Revolving Digits Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...

  2. 【HDU4333】Revolving Digits(扩展KMP+KMP)

    Revolving Digits   Description One day Silence is interested in revolving the digits of a positive i ...

  3. 字符串(扩展KMP):HDU 4333 Revolving Digits

    Revolving Digits Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. HDU - 4333 :Revolving Digits (扩展KMP经典题,问旋转后有多少个不同的数字小于它本身,等于它本身,大于它本身。)

    One day Silence is interested in revolving the digits of a positive integer. In the revolving operat ...

  5. Revolving Digits(hdu4333)

    Revolving Digits Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. HDU 4333 Revolving Digits 扩张KMP

    标题来源:HDU 4333 Revolving Digits 意甲冠军:求一个数字环路移动少于不同数量 等同 于的数字 思路:扩展KMP求出S[i..j]等于S[0..j-i]的最长前缀 推断 nex ...

  7. hdu4333 Revolving Digits(扩展kmp)

    Revolving Digits Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. 扩展KMP - HDU 4333 Revolving Digits

    Revolving Digits Problem's Link Mean: 给你一个字符串,你可以将该字符串的任意长度后缀截取下来然后接到最前面,让你统计所有新串中有多少种字典序小于.等于.大于原串. ...

  9. Revolving Digits(hdu 4333)

    题意:就是给你一个数字,然后把最后一个数字放到最前面去,经过几次变换后又回到原数字,问在这些数字中,比原数字小的,相等的,大的分别有多少个.比如341-->134-->413-->3 ...

随机推荐

  1. AutoMapper之ABP项目中的使用介绍

    最近在研究ABP项目,昨天写了Castle Windsor常用介绍以及其在ABP项目的应用介绍 欢迎各位拍砖,有关ABP的介绍请看阳光铭睿 博客 AutoMapper只要用来数据转换,在园里已经有很多 ...

  2. 使用hovertree菜单作为后台导航

    hovertree是一个jquery菜单插件,官方网址:http://keleyi.com/jq/hovertree/ ,可以登录该网址体验效果. 0.1.3版本:http://keleyi.com/ ...

  3. 移动端全兼容的flexbox速成班

    说起flexbox,都算是件陈年旧事了,它是2009年W3C提出的一种全新的可伸缩的CSS布局方式.依赖flexbox,我们可以更简单,高效的完成可伸缩式页面的布局. 业界与flexbox的相关教程文 ...

  4. Android Gson的使用总结

    1.概念 Gson是谷歌发布的一个json解析框架 2.如何获取 github:https://github.com/google/gson android studio使用 compile 'com ...

  5. iOS tableViewCell自适应高度 第三发类库

    在github中有许多大牛封装好的第三发类库,其中有个自适应cell高度的类库 下载地址:https://github.com/gsdios/SDAutoLayout model类 commentsM ...

  6. iOS 动画绘制线条颜色渐变的折线图

    效果图 .................... 概述 现状 折线图的应用比较广泛,为了增强用户体验,很多应用中都嵌入了折线图.折线图可以更加直观的表示数据的变化.网络上有很多绘制折线图的demo,有 ...

  7. 关于git,你需要知道一点命令

    最近有朋友经常问git的一些操作,写在这里与大家分享,以后也不用一一解释了.惯例,这是基础分享,从安装开始说起: 安装: 去这里 https://git-scm.com/ 找到你所需要的版本,下载并安 ...

  8. TeamCity实战(1):准备工作

    环境: Windows Server 2008 R2 SP1(不会再有SP2,参考这里:http://www.techspot.com/news/50599-microsoft-wont-releas ...

  9. Web基础知识

    这学期学了Web技术这门课,但对这门课是做什么的.有什么用处并不了解,教材是Asp.net实用网站开发,对我这样的初学者大概是深了一点,所以决定对Web技术的背景知识做下整理. 1.Web工作原理 W ...

  10. JavaScript:内存泄露、性能调优

    1.在进行JS内存泄露检查之前,先要了解JS的内存管理: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Manageme ...