【hdu 4333】Revolving Digits
【链接】http://acm.hdu.edu.cn/showproblem.php?pid=4333
【题意】
【题解】
2121 1212 2121
【错的次数】
【反思】
【代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); const int N=20e4;
int Next[N+10],extend[N+10],lens,lent,f[N];
char S[N+10],T[N+10]; void makenext(int m){
int a = 0;
Next[0] = lens;
while(a < lens - 1 && S[a] == S[a + 1]) a++;
Next[1] = a;
a = 1;
for(int k = 2; k < lens; k ++) {
int p = a + Next[a] - 1,L = Next[k - a];
if( (k - 1) + L >= p) {
int j = (p - k + 1) > 0 ? (p - k + 1) : 0;
while(k + j < lens && S[k + j] == S[j]) j++;
Next[k] = j;
a = k;
} else
Next[k] = L;
}
} void GetNext(const char *T){
int a=0;
int MinLen = lens < lent ? lens : lent;
while(a < MinLen && S[a] == T[a] ) a++;
extend[0]=a;
a=0;
for(int k=1;k < lent;k++){
int p=a+extend[a]-1,L = Next[k-a];
if((k-1)+L>=p){
int j=(p-k+1)>0? (p-k+1):0;
while(k + j < lent && T[k+j] == S[j]) j++;
extend[k]=j;
a=k;
}
else extend[k]=L;
}
} void getf(const char *s){
f[0] = 0,f[1] = 0;
int j = 0;
rep1(i,1,lens-1){
while (j > 0 && s[i]!=s[j]) j = f[j];
f[i+1] = (s[i]==s[j]?++j:0);
}
} int main(){
//Open();
int TT,kk = 0;
ri(TT);
while (TT--){
rs(S);
lens = strlen(S),lent = 2*lens;
makenext(lens);
getf(S);
int ju = lens-f[lens],tt;
if (lens%ju==0)
tt = lens/ju;
else
tt = 1;
rep1(i,0,lens-1)
T[i] = S[i];
rep1(i,lens,2*lens-1)
T[i] = T[i-lens];
GetNext(T);
int a = 0,b = 0,c = 0;
rep1(i,0,lens-1)
if (extend[i]>=lens)
b++;
else if (S[extend[i]] < T[i+extend[i]])
a++;
else if (S[extend[i]] > T[i+extend[i]])
c++;
os("Case ");oi(++kk);os(": ");oi(c/tt);oc;oi(b/tt);oc;oi(a/tt);
puts("");
}
return 0;
}
【hdu 4333】Revolving Digits的更多相关文章
- HDU - 4333 :Revolving Digits (扩展KMP经典题,问旋转后有多少个不同的数字小于它本身,等于它本身,大于它本身。)
One day Silence is interested in revolving the digits of a positive integer. In the revolving operat ...
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】
[把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...
- 【HDU 2196】 Computer(树的直径)
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...
- 【HDU 2196】 Computer (树形DP)
[HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...
- 【HDU 5145】 NPY and girls(组合+莫队)
pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...
- 【HDU4333】Revolving Digits(扩展KMP+KMP)
Revolving Digits Description One day Silence is interested in revolving the digits of a positive i ...
- 【hdu 1043】Eight
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...
随机推荐
- TRIZ系列-创新原理-7-嵌套原理
原理表述例如以下: 1)把一个物体嵌入另外一个物体.然后将这两个物体再嵌入第三个物体,以此类推. 这个原理又叫俄罗斯娃原理,目的是在不影响原有功能的情况下: A) 在须要时.能够降低系统的体积和便于携 ...
- git帮助命令
git帮助命令 零.自己实例 cd D://software/code/PHP/phpStudy/PHPTutorial/WWW/github/m_Orchestrate git checkout - ...
- 25.内置API
转自:https://www.cnblogs.com/best/tag/Angular/ 3.1.数据转换 示例: 默认情况JavaScript中对象是传引用的: var tom={name:&quo ...
- Linux下Rootkit的另类检测
Linux下Rootkit的另类检测 当黑客获取管理员权限时,首先是抹掉入侵系统的相关记录,并且隐藏自己的行踪,要实现这一目的最常用的方法就是使用Rootkits,简单的说,Rootkits是一种经 ...
- VS初始化设置
来源于网上整理和 书<aps.net mvc企业级实战>中. 1.vs模版 版权注释信息 1.我的电脑上VS2015安装在D盘中,所以找的目录为:D:\Program Files (x86 ...
- js 判断对touch事件支持
$.support = (function() { var support = { touch: !!(('ontouchstart' in window) || window.DocumentTou ...
- Python正则表达式初识(三)
前几天给大家分享了Python正则表达式基础(一)和Python正则表达式基础(二),感兴趣的小伙伴可以点击进去学习,今天继续给大家分享Python正则表达式基础. 1.正则表达式特殊字符“+”,其代 ...
- caioj 1063 动态规划入门(一维一边推1:美元和马克)
这道题一开始我是这么想的 最后的答案肯定是某次的马克换回来的,但这个该怎么确定?? 实际上应该把范围缩小,只看最后一次和倒数第二次之间有什么联系. 可以发现,只有两种可能,最后一天换或者不换.换的话就 ...
- https soap链接示例
1.先安装soap扩展sudo yum install php-soap 2.安装openssL 3.function issure($sn){//通过soap链接接口 进行确认是否是正确的sn码 ...
- CSDN博客给我带来的一些诱惑和选择机会(二):HR“邀请于我”,猎头“有求于我”
上次,2013年10月8日 ,分享了一篇颇具"正能量"的文章CSDN博客给我带来的一些诱惑和选择机会,获得了很好的正面效果. 10月份,又发生了很多有趣.有意义的事情. 其中,有一 ...