Hdu 4333 Revolving Digits(Exkmp)
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)的更多相关文章
- HDU 4333 Revolving Digits 扩张KMP
标题来源:HDU 4333 Revolving Digits 意甲冠军:求一个数字环路移动少于不同数量 等同 于的数字 思路:扩展KMP求出S[i..j]等于S[0..j-i]的最长前缀 推断 nex ...
- 字符串(扩展KMP):HDU 4333 Revolving Digits
Revolving Digits Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 扩展KMP - HDU 4333 Revolving Digits
Revolving Digits Problem's Link Mean: 给你一个字符串,你可以将该字符串的任意长度后缀截取下来然后接到最前面,让你统计所有新串中有多少种字典序小于.等于.大于原串. ...
- HDU 4333 Revolving Digits 扩展KMP
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4333 题意:给以数字字符串,移动最后若干位到最前边,统计得到的数字有多少比原来大,有多少和原来同样,有多少 ...
- HDU - 4333 Revolving Digits(扩展KMP)
http://acm.hdu.edu.cn/showproblem.php?pid=4333 题意 一个数字,依次将第一位放到最后一位,问小于本身的数的个数及等于本身的个数和大于本身的个数,但是要注意 ...
- 【扩展kmp+最小循环节】HDU 4333 Revolving Digits
http://acm.hdu.edu.cn/showproblem.php?pid=4333 [题意] 给定一个数字<=10^100000,每次将该数的第一位放到放到最后一位,求所有组成的不同的 ...
- HDU 4333 Revolving Digits
扩展KMP的应用 我们发现本题的关键在于如何高效的判断两个同构字符串的大小关系,想到如果能够预处理出每一个同构字符串与原字符串的最长公共前缀,那么直接比较它们不一样的部分就好,扩展KMP正好是用来处理 ...
- HDU 4333 Revolving Digits [扩展KMP]【学习笔记】
题意:给一个数字,每一次把它的最后一位拿到最前面,一直那样下去,分别求形成的数字小于,等于和大于原来数的个数. SAM乱搞失败 当然要先变SS了 然后考虑每个后缀前长为n个字符,把它跟S比较就行了 如 ...
- hdu 4333"Revolving Digits"(KMP求字符串最小循环节+拓展KMP)
传送门 题意: 此题意很好理解,便不在此赘述: 题解: 解题思路:KMP求字符串最小循环节+拓展KMP ①首先,根据KMP求字符串最小循环节的算法求出字符串s的最小循环节的长度,记为 k: ②根据拓展 ...
随机推荐
- 汉诺塔递推HDU2064
题意: 移动木头盘不能a到c,必须a到b到c. 问你移动次数. 假设将n层塔从A经B挪到C需要f[n]步.那么具体的移动过程可以这样看:将上面n-1层从A经B挪到C需要f[n-1]步,再将第n层从A挪 ...
- 从用户在浏览器输入URL回车之后,浏览器都做了什么
在直接列出执行的步骤之前先来普及几个知识,相信了解完这些知识之后会对前后端的交互有更深入的理解. 1.TCP连接 TCP:Transmission Control Protocol, 传输控制协议,是 ...
- windows下memcache扩展安装和搭建
### windows下memcache扩展安装和搭建 背景:在做微信公众号的开发时,token的有效期为7200秒,所以需要对token进行保存,在这选择了memcache作为缓存工具 memcac ...
- 数值分析-Legendre正交多项式 实现函数逼近
数值分析-Legendre正交多项式 实现函数逼近 2016年12月18日 21:27:54 冰三点水 阅读数 4057 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请 ...
- Python利用PIL将数值矩阵转化为图像
要求:输入一个n*n的矩阵,矩阵包括从-1到1的浮点数,将其转化为可视化图像 调库 from PIL import Image import numpy as np import math 载入图像, ...
- JS 编程艺术
JS艺术片段剪贴 getFullDate: function (date) { //返回 YYYY年MM月DD日 var year = month = day = ' '; if (isNaN(dat ...
- Js-带进度条的轮播图
带进度条的轮播图--原生JS实现 实现了图片自动轮播,左右按钮实现图片左右转换,下方原点或者缩小图点击选择其中的某一张图片,然后有红条实现图片的进度. <div class="cont ...
- Linux软链接创建及删除
1.创建软链接 具体用法是:ln -s [源文件] [软链接文件]. [root@localhost folder]# pwd /tmp/folder [root@localhost fol ...
- 13.SpringMVC核心技术-异常处理
常用的SpringMVC异常处理方式主要是三种: 1.使用系统定义好的异常处理器 SimpleMappingExceptionResolver 2.使用自定义异常处理器 3.使用异常处理注解 Si ...
- Spring Cloud(一)服务的注册与发现(Eureka)
Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中涉及的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全局锁.决策竞选.分布式会话和集 ...