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. [moka同学笔记]五、Yii2.0课程笔记(魏曦老师教程)[审核功能]

  2. Socket编程——客户端,服务器端的读写操作

    URL网络编程,最大的特征就是一对一的响应! 1:客户端“写”,服务器端用于“读” package coreBookSocket2; import java.io.InputStreamReader; ...

  3. UDS(ISO14229-2006) 汉译(No.0 前言)

    UDS protocol 前言 ISO(国际标准化组织)是国际标准机构(ISO成员体)的世界性联合会.国际标准的拟定工作通常由ISO技术委员会负责.为每一个主题而建立的技术委员会由对其感兴趣的成员机构 ...

  4. javascript中BOM部分基础知识总结

    一.什么是BOM      BOM(Browser Object Document)即浏览器对象模型.      BOM提供了独立于内容 而与浏览器窗口进行交互的对象:      由于BOM主要用于管 ...

  5. 使用 Arduino 和 LM35 温度传感器监测温度

    上一篇玩儿了一下Arduino入门,这次再进一步,用一下LM35温度传感器来监测当前温度.LM35温度传感器已经在Arduino入门套件里包含了,就是那个有三个脚的小黑块儿. 我们先把这些东西连起来. ...

  6. ThinkPHP实现对数据库的增删改查

    好久都没有更新博客了,之前老师布置的任务总算是现在可以说告一段落了,今天趁老师还没提出其他要求来更新一篇博客. 今天我想记录的是我之前做项目,自己所理解的ThinkPHP对数据库的增删改查. 首先要说 ...

  7. iOS面试题总结(一)

    面试题总结 1.#import 跟#include.@class有什么区别?#import<> 跟 #import""又什么区别? include和#import都能完 ...

  8. .NET轻量级RPC框架:Rabbit.Rpc

    最近准备写一个.NET的管理平台应用在公司,由于存在大量的Client => Server,Server => Client的请求需求在加上之前一直接触了解过RpcClient组件的开发, ...

  9. cglib动态代理

    代理即为访问对象添加一层控制层,使其间接化,控制层可以为对象访问添加操作属性. cglib:Code Generation library, 基于ASM(java字节码操作码)的高性能代码生成包 被许 ...

  10. MySQL Nested-Loop Join算法学习

    不知不觉的玩了两年多的MySQL,发现很多人都说MySQL对比Oracle来说,优化器做的比较差,其实某种程度上来说确实是这样,但是毕竟MySQL才到5.7版本,Oracle都已经发展到12c了,今天 ...