【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 ...
随机推荐
- bzoj 1010 (单调决策优化)
能够非常好的证明单调决策性质.用 记sum[i]=sigma(C[1],C[2].....C[k]);f[i]=sum[i]+i; c=l-1; 有转移dp[i]=min( dp[j]+(f[i ...
- Virtual Directory in IIS
https://www.iis.net/configreference/system.applicationhost/sites/site/application/virtualdirectory O ...
- 19.浏览器Window服务($window)
转自:https://www.cnblogs.com/best/tag/Angular/ 引用浏览器的window对象.默认浏览器的window是全局的根对象. 示例代码: <!DOCTYPE ...
- AngularJS初接触
todo.json [ { "action": "Buy Flowers", "done": false }, { "action ...
- BZOJ 1503 treap
思路: treap (算是基本操作吧-..) 加减的操作数很少 就暴力好啦 每回判断一下最小的数是不是比M小 如果是 就删,继续判断 搞定. //By SiriusRen #include <c ...
- 解决Esxi5下安装Windows 8的问题
在VM8工作站版下安装windows 8没有问题,可是到了Esxi5下,非得安装补丁不可.补丁下载地址: http://kb.vmware.com/selfservice/microsites/sea ...
- Git 操作笔记
¥先放个地址:这个视频超详细 https://www.bilibili.com/video/av10475153 分了2部分: 1是GitHub的功能介绍:2是pc端+doc命令的操作+发布个人网站 ...
- 分享一个tom大叔的js 深入理解系列 (有助于提升)
http://www.cnblogs.com/TomXu/archive/2011/12/15/2288411.html#3620172
- SQL函数-stuff()
select stuff(列名,开始位置,长度,替代字符串) 用于删除指定长度的字符串,并可以在指定长度的地方插入新的字符: 在指定长度的地方添加新的字符
- 网络爬虫与web之间的访问授权协议——Robots
网站的管理者们通常会有这样一种心态:一方面期待百度.Google这样的搜索引擎来抓取网站的内容,另一方面又很厌恶其他来路不明的网络爬虫抓取自己的信息.正是因为这样,才有“好爬虫”.“坏爬虫”这样的说法 ...