Revolving Digits

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

Total Submission(s): 25518 Accepted Submission(s): 5587

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

2012 Multi-University Training Contest 4

/*
exkmp.
把原串copy一遍.
先处理出每个后缀与原串的最长公共前缀长度.
Next[i]表示以i为始的最长公共前缀长度.
然后做exkmp只比较每个后缀的前len个字符.
然后比较Next[i]与len的关系.
Next[i]>=len显然匹配前i个字符成功.
t[Next[i]]>s[i+Next[i]]说明该串较小.
(s串为t串copy后的串).
t[Next[i]]<t[i+Next[i]]说明该串较大.
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define MAXN 200001
using namespace std;
char t[MAXN],s[MAXN];
int Next[MAXN],tot,tot1,tot2,tot3;
void kmp()
{
int l=strlen(t);
int i=0,j=-1;
Next[i]=-1;
while(i<l)
{
if(j==-1||t[i]==t[j]) i++,j++,Next[i]=j;
else j=Next[j];
}
}
void get_next()
{
int a=0,l=strlen(t);
Next[0]=l;
while(a<l-1&&t[a]==t[a+1]) a++;
Next[1]=a;a=1;
for(int k=2;k<l;k++)
{
int p=a+Next[a]-1,L=Next[k-a];
if(k+L-1>=p){
int j=max(p-k+1,0);
while(k+j<l&&t[k+j]==t[j]) j++;
Next[k]=j;
a=k;
}
else Next[k]=L;
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",t);
int l=strlen(t);
kmp();
int k=l-Next[l],x;
if(l%k==0) x=l/k;
else x=1;
for(int i=0;i<l;i++) t[l+i]=t[i];
get_next();
tot1=tot2=tot3=0;
for(int i=0;i<l;i++)
{
if(Next[i]>=l) tot2++;
else if(t[Next[i]]>t[i+Next[i]]) tot1++;
else if(t[Next[i]]<t[i+Next[i]]) tot3++;
}
tot1/=x,tot2/=x,tot3/=x;
printf("Case %d: %d %d %d\n",++tot,tot1,tot2,tot3);
}
return 0;
}

Hdu 4333 Revolving Digits(Exkmp)的更多相关文章

  1. HDU 4333 Revolving Digits 扩张KMP

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

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

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

  3. 扩展KMP - HDU 4333 Revolving Digits

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

  4. HDU 4333 Revolving Digits 扩展KMP

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

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

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

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

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

  7. HDU 4333 Revolving Digits

    扩展KMP的应用 我们发现本题的关键在于如何高效的判断两个同构字符串的大小关系,想到如果能够预处理出每一个同构字符串与原字符串的最长公共前缀,那么直接比较它们不一样的部分就好,扩展KMP正好是用来处理 ...

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

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

  9. hdu 4333"Revolving Digits"(KMP求字符串最小循环节+拓展KMP)

    传送门 题意: 此题意很好理解,便不在此赘述: 题解: 解题思路:KMP求字符串最小循环节+拓展KMP ①首先,根据KMP求字符串最小循环节的算法求出字符串s的最小循环节的长度,记为 k: ②根据拓展 ...

随机推荐

  1. 学习BM算法

    BM算法: 希望大家别见怪,当前博客只用于个人记录所用. [例题]Poor God Water 题意: 有肉,鱼,巧克力三种食物,有几种禁忌,对于连续的三个食物, 1.这三个食物不能都相同: 2.若三 ...

  2. 使用jenkins 构建时,字体图标报错的问题。

    最近一个项目开发中,我们在本地进行项目打包时,可以正常打包. 但是在使用jenkins构建时,一直报错,提示无法加载字体文件.can't resolve module '....xxxx.TTF ' ...

  3. 深入理解Java自动装箱拆箱机制

    1.自动装箱与拆箱的定义 装箱就是自动将基本数据类型转换为包装器类型(int-->Integer): 拆箱就是自动将包装器类型转换为基本数据类型(Integer-->int). Java中 ...

  4. 微信小程序转发事件

    和生命周期是同级,在.js文件里面设置 // 分享按钮 onShareAppMessage: function () { return { title: '前端伪大叔', path: "/p ...

  5. Linux学习(二)-Xshell 5和Xftp 5的安装和使用

    (一)软件介绍: (1)Xshell: Xshell通过互联网可以连接到远程的服务器,然后通过模拟终端来实现对服务器的各种操作,而且这款软件可以很好的解决中文乱码问题,非常的方便快捷. (2)Xftp ...

  6. django form 和modelform样式设置

      目录 1.form通过attr设置属性 2.输入框设置表单状态 3.modelform的使用 4.结合modelform 使用for循环生成输入框 5.基于init构造方法设置样式 6.基本增删改 ...

  7. asp.net ListView控件的简单实用和配置

    1 web窗体界面代码 ItemType:控件要绑定的实体模型 SelectMethod:控件获取实体集合的后台方法 DataKeyNames:实体的主键 UpdateProduct:设置跟新的方法 ...

  8. vue项目中引入animate.css和wow.js

    本文转自:https://blog.csdn.net/liyunkun888/article/details/85003152 https://www.zhuimengzhu.com/content/ ...

  9. qt打包发布

    需要用到qt自带工具windeployqt.exe 安装 以qt 5.8.0为例 安装qt-opensource-windows-x86-mingw530-5.8.0.exe即可 构建Release版 ...

  10. Python: NumPy, Pandas学习资料

    NumPy 学习资料 书籍 NumPy Cookbook_[Idris2012] NumPy Beginner's Guide,3rd_[Idris2015] Python数据分析基础教程:NumPy ...