隐藏页面特效

Revolving Digits[EXKMP]

1|0Revolving 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+10; int cas,_,Next[N]; char T[N]; void kmp(int l){ int i=0,j=-1;Next[i]=j; while(i<l){ if(j==-1||T[i]==T[j]) Next[++i]=++j; else j=Next[j]; } } void get_next(int Tlen){ int a=0; Next[0]=Tlen; while(a<Tlen-1&&T[a]==T[a+1]) a++; Next[1]=a;a=1; for(int k=2;k<Tlen;k++){ int p=a+Next[a]-1,L=Next[k-a]; if(k+L-1>=p){ int j=(p-k+1>0)?p-k+1:0; 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=1;cas<=_;cas++){ scanf("%s",T); int len=strlen(T); kmp(len); int k=len-Next[len],tt; if(len%k==0) tt=len/k; else tt=1; for(int i=0;i<len;i++) T[len+i]=T[i]; get_next(len*2); int num1=0,num2=0,num3=0; for(int i=0;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 0; }

 


__EOF__

本文作者shenben
本文链接https://www.cnblogs.com/shenben/p/6253935.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   神犇(shenben)  阅读(270)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示