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.

InputThe 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.OutputFor 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

题意:给定一个数字,问旋转后有多少个不同的数字小于它本身,等于它本身,大于它本身。

思路:比较两个数的大小时,我们可以跳过前面相等的数字,直接比较第一个不相等的数字,那么就可以用exKMP,得到expand的位置,然后比较第一个不相等的位置。因为是求不同的数字的贡献,我们还要注意循环节。

#include<bits/stdc++.h>
using namespace std;
const int maxn=;
int Next[maxn],ans1,ans2,ans3; char c[maxn];
void exKMP(){
int i,len=strlen(c+);
Next[]=len;
for(int i=;i<=len;i++) c[i+len]=c[i];
for(i=;i+<len+len&&c[i+]==c[i+];i++);
Next[]=i; int a=;
for(int k=;k<=len+len;k++){
int p=a+Next[a]-, L=Next[k-a+];
if(L>=p-k+){
int j=(p-k+)>?(p-k+):;
while(k+j<=len+len&&c[k+j]==c[j+]) j++;
Next[k]=j, a=k;
}
else Next[k]=L;
}
ans1=ans2=ans3=;
for(int i=;i<=len;i++){
if(Next[i]>=len){ if(ans2) break; ans2++; }
else {
if(c[i+Next[i]]<c[Next[i]+]) ans1++;
else ans3++;
}
}
}
int main(){
int T,Cas=;
scanf("%d",&T);
while(T--){
scanf("%s",c+);
exKMP();
printf("Case %d: %d %d %d\n",++Cas,ans1,ans2,ans3);
}
return ;
}

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

  1. HDU 4333 Revolving Digits 扩展KMP

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4333 题意:给以数字字符串,移动最后若干位到最前边,统计得到的数字有多少比原来大,有多少和原来同样,有多少 ...

  2. HDU 4333 Revolving Digits [扩展KMP]【学习笔记】

    题意:给一个数字,每一次把它的最后一位拿到最前面,一直那样下去,分别求形成的数字小于,等于和大于原来数的个数. SAM乱搞失败 当然要先变SS了 然后考虑每个后缀前长为n个字符,把它跟S比较就行了 如 ...

  3. HDU 4333 Revolving Digits 扩张KMP

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

  4. 扩展KMP - HDU 4333 Revolving Digits

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

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

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

  6. HDU - 4333 Revolving Digits(扩展KMP)

    http://acm.hdu.edu.cn/showproblem.php?pid=4333 题意 一个数字,依次将第一位放到最后一位,问小于本身的数的个数及等于本身的个数和大于本身的个数,但是要注意 ...

  7. 【扩展kmp+最小循环节】HDU 4333 Revolving Digits

    http://acm.hdu.edu.cn/showproblem.php?pid=4333 [题意] 给定一个数字<=10^100000,每次将该数的第一位放到放到最后一位,求所有组成的不同的 ...

  8. HDU - 4333 Revolving Digits(拓展kmp+最小循环节)

    1.给一个数字字符串s,可以把它的最后一个字符放到最前面变为另一个数字,直到又变为原来的s.求这个过程中比原来的数字小的.相等的.大的数字各有多少. 例如:字符串123,变换过程:123 -> ...

  9. hdu4333 Revolving Digits(扩展kmp)

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

随机推荐

  1. 关于Python字符编码encode和decode

    (注:本文部分内容摘自互联网,由于作者水平有限,不足之处,还望留言指正.) 记得几天前,部门的一个小姑娘问我,怎么她Python打印出来的中文信息都乱码了?我走过去,略思一二,瞬间给她搞定,其实这是字 ...

  2. SQL SERVER 索引中聚集索引分析和Transact-SQL语句优化

    一. 聚集索引B树分析1.聚集索引按B树结构进行组织的,索引B树种的每一页称为一个索引节点.B树的顶端节点称为根节点.  索引中的低层节点称为叶节点.根节点与叶节点之间的任何索引级别统称为中间级.在聚 ...

  3. 20145201 《Java程序设计》第一周学习总结(修改)

    # 20145201 <Java程序设计>第一周学习总结 ## 教材学习内容总结 万事开头难,终于开始学习了Java.寒假的时候看到老师的要求确实有点慌,但是这周翻开书,从书本知识第一行学 ...

  4. JavaWeb HTML

    1. HTML介绍 1.1. 什么是HTML HTML的全称为Hyper Text Markup Language,译为超文本标记语言. 超文本,就是指页面内可以包含图片.链接,甚至音乐.程序等非文字 ...

  5. PHP正则表达式 /i, /is, /s, /isU等 都是些什么东西呢?

    PHP正则表达式 /i, /is, /s, /isU等 都是些什么东西呢? i 不区分大小写 s 模式中的圆点元字符(.)匹配所有的字符,包括换行符 x 模式中的空白字符除了被转义的或在字符类中的以外 ...

  6. JNI简单步骤01

    1.环境变量 1.1.相应的环境变量中,加入如下内容:(Windows) (1).ClASSPATH中输入 : ".;C:\Program Files\Java\jdk1.7.0_07\jr ...

  7. 谈谈你对Glide和Picasso他们的对比的优缺点

    1.Picasso和Glide的withi后面的参数不同 Picasso.with(这里只能传入上下文)     . Glide.with,后面可以传入上下文,activity实例,FragmentA ...

  8. python学习笔记(excel+requests)

    已经可以对excel简单的操作后 可以开始通过excel写测试用例 读取用例 执行用例 提前写好execl 如图: 下面是代码: #!/usr/bin/env python # -*- coding: ...

  9. JS获取元素计算过后的样式

    获取元素计算过后的样式 Window.getComputedStyle() 方法会在一个元素应用完有效样式且计算完所有属性的基本值之后给出所有 CSS 属性的值. 语法: let style = wi ...

  10. oracle:查询数据表是否存在

    oracle:查询数据表是否存在 select count(*) as NUM from all_tables where table_name = '{$table}' 或者: select cou ...