Revolving Digits
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 24215 Accepted Submission(s): 5268
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
题意:将一个数的每一个后缀移到前面和剩下的数字组成新的数字,求这些数字中比原来数字大的,相等的,小的,且不能重复的个数.
思路:将原来的串复制到原窜的后面,那么这样就可以得到,将后缀移到前面的相同的字串,其实就相当于将后缀串移到前面。那后一般的思想是,暴力比较。
假设原串的长度为l,那么新串就为2*l;拿原串与新串[1,l]比较。这样可以用EXKMP来优化,如果在这个点处,extend[i]>=l,那么这个点处往后再数l-1个点时,这个数就和
原数相等,否则小于的话就比较tt[i+extend[i]]-'0'>cc[extend[i]+1]-'0'的大小就好了。最后去重的话,用KMP的next数组,求下循环节,再每个数除循环节就可以了。
还有一种去重复的就是,最后相等的答案肯定是1,所以要除的那个数就是相等的个数;
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include