【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 ...
随机推荐
- linux(debian/ubuntu)下连接安卓手机--小米4为例
更改:如今小米连接Ubuntu等Linux系统,直接改动手机上的连接方式就可以. --------------------------------------------- 因为安卓手机底层就是lin ...
- vue2.0-transition多个元素
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 23. Angular 中用 a 标签 href 路由时在浏览器中显示异常 "%2F" 路由失败问题1
这个是angular1.6默认给hash路由上添加了!(感叹号),导致出错,修改方法如下(添加配置,去掉默认前缀感叹号): angular.module('routingDemoApp',['ng ...
- Important Abstractions and Data Structures
For Developers > Coding Style > Important Abstractions and Data Structures 目录 1 TaskRunne ...
- ImportError: cannot import name pxssh
Traceback (most recent call last): File "/root/Desktop/JuniperBackdoor-master/JuniperBackdoor.p ...
- 【Linux下安装配置Jupyter】
""" 第一步 安装 """ pip3 install -i https://pypi.douban.com/simple jupyter ...
- 及格的产品vs优秀的产品
类似的产品,做了同样的一个功能,但是,我们还是可以很明显的感受到不同,这种不同我们常常把他叫做「用户体验」. 来看看2组类似产品相似功能的设计: 识别到歌名vs还可以滚动展示歌词 在很早的时候就存在一 ...
- 51nod 多重背包问题(二进制优化)
有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放在容量为W的背包里,每种物品的体积为W1,W2......Wn(Wi为整数),与之相对应的价值为P1,P2......Pn(Pi ...
- PHP定时执行任务
ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行. set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去 $int ...
- spring 使用c3po连接池
1 数据源:能够简单理解为数据的来源. 2 连接池:是缓存一定数量的数据库连接,当程序须要数据库连接的时候,直接在连接池中获取空暇的连接,使用完再放回连接池中,此连接又变成空暇状态,等待下一次连接. ...