HDU4333[Revolving Digits]
来源:互联网 发布:vs2015写c语言 编辑:程序博客网 时间:2024/06/05 19:13
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
solution: 扩展kmp
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;#define N 100010char t[N*2];int nxt[N], lent, lens;void get_nxt(){ int i=0, j=-1; nxt[0]=-1; while( i<lent ){ if( j==-1||t[i]==t[j] ) nxt[++i]=++j; else j=nxt[j]; }}void get_ext(){ int a=0, i=1; nxt[0]=lent; while( a+1<lens && t[a]==t[a+1] )++a; nxt[1]=a; a=1; while( ++i<lent ){ int mx= a+nxt[a]-1; nxt[i]=min( nxt[i-a], max(0,mx-i+1) ); while( i+nxt[i]<lens && t[nxt[i]]==t[i+nxt[i]]) ++nxt[i]; if( i+nxt[i]>a+nxt[a] ) a=i; }}int main(){ int T, num=0; scanf("%d",&T); while( T-- ){ scanf("%s", t); lent=strlen(t); lens=lent+lent; get_nxt(); int tmp=lent%(lent-nxt[lent])==0 ? lent/(lent-nxt[lent]):1; for ( int i=0; i<=lent; i++ ) t[i+lent]=t[i]; get_ext(); int a,b,c; a=b=c=0; for ( int i=0; i<lent; i++ ) if( nxt[i]>=lent ) b++; else if ( t[nxt[i]]<t[i+nxt[i]] ) c++; else a++; cout<<"Case "<<++num<<": "<<a/tmp<<' '<<b/tmp<<' '<<c/tmp<<endl; }}
- hdu4333----Revolving Digits
- hdu4333 Revolving Digits - exkmp
- HDU4333[Revolving Digits]
- hdu4333 Revolving Digits(扩展kmp)
- hdu4333-拓展kmp-Revolving Digits
- HDU4333:Revolving Digits(拓展kmp)
- hdu4333 Revolving Digits(kmp+exkmp)
- HDU4333 Revolving Digits(KMP+扩展KMP)
- hdu4333 Revolving Digits(扩展kmp+kmp最小循环节)
- Revolving Digits
- Revolving Digits (扩展KMP)
- HDOJ 4333 Revolving Digits
- hdu 4333 Revolving Digits
- HDU 4333 Revolving Digits
- hdu 4333 Revolving Digits
- HDU 4333 Revolving Digits
- hdu 4333 Revolving Digits
- HDU 4333 Revolving Digits
- Oracle 11G在用EXP 导出时,空表不能导出解决
- hdu 6055 Regular polygon
- 深入剖析 iOS 性能优化
- Python 写3D花
- Python程序-2
- HDU4333[Revolving Digits]
- const、readonly及静态构造的用法
- 世界上没有怀才不遇这件事,关键是找准你的优势
- 有重复元素的排列问题
- Linux下动态库(.so)和静态库(.a)
- UVA1608Non-boringSquence
- Listview 里面的按钮点击 复用问题
- JSP上传图片源码
- caffe (11) 其他功能