String Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3183    Accepted Submission(s): 1295

Problem Description
Give
you a string with length N, you can generate N strings by left shifts.
For example let consider the string “SKYLONG”, we can generate seven
strings:
String Rank
SKYLONG 1
KYLONGS 2
YLONGSK 3
LONGSKY 4
ONGSKYL 5
NGSKYLO 6
GSKYLON 7
and lexicographically first of them is GSKYLON, lexicographically last is YLONGSK, both of them appear only once.
  Your
task is easy, calculate the lexicographically fisrt string’s Rank (if
there are multiple answers, choose the smallest one), its times,
lexicographically last string’s Rank (if there are multiple answers,
choose the smallest one), and its times also.
 
Input
  Each line contains one line the string S with length N (N <= 1000000) formed by lower case letters.
 
Output
Output
four integers separated by one space, lexicographically fisrt string’s
Rank (if there are multiple answers, choose the smallest one), the
string’s times in the N generated strings, lexicographically last
string’s Rank (if there are multiple answers, choose the smallest one),
and its times also.
 
Sample Input
abcder
aaaaaa
ababab
 
Sample Output
1 1 6 1
1 6 1 6
1 3 2 3
求循环节,并求字典序最大最小出现的次数
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
char a[];
int p[];
void getnext()
{
int i=,j=-;
p[]=-;
while(a[i]!='\0')
{
if(j==- || a[i]==a[j])
p[++i]=++j;
else j=p[j];
}
}
int check(bool flag)
{
int i=,j=,k=;
while(i<strlen(a) && j<strlen(a) && k<strlen(a))
{
int t=a[(j+k)%strlen(a)]-a[(i+k)%strlen(a)];
if(t==) k++;
else
{
if(flag)
{
if(t>) j+=k+;
else i+=k+;
}
else
{
if(t<) j+=k+;
else i+=k+;
}
if(i==j) j++;
k=;
}
}
return min(i,j);
}
int main()
{
while(scanf("%s",a)!=EOF)
{
int minn=check(true);
int maxn=check(false);
getnext();
int ans=(strlen(a)%(strlen(a)-p[strlen(a)]))==?strlen(a)/(strlen(a)-p[strlen(a)]):;
printf("%d %d %d %d\n",minn+,ans,maxn+,ans);
}
return ;
}

HDU 3374 String Proble的更多相关文章

  1. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  2. HDU 3374 String Problem(KMP+最大/最小表示)

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. HDU - 3374 String Problem (kmp求循环节+最大最小表示法)

    做一个高产的菜鸡 传送门:HDU - 3374 题意:多组输入,给你一个字符串,求它最小和最大表示法出现的位置和次数. 题解:刚刚学会最大最小表示法,amazing.. 次数就是最小循环节循环的次数. ...

  4. HDU 3374 String Problem (KMP+最小最大表示)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3374 [题目大意] 给出一个字符串,求出最小和最大表示是从哪一位开始的,并且输出数量. [题解] ...

  5. HDU 3374 String Problem(KMP+最大(最小)表示)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题目大意:给出一个字符串,依次左移一个单位形成一堆字符串,求其字典序最小和最大的字符串需要左移多 ...

  6. hdu 3374 String Problem (kmp+最大最小表示法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题目大意:输出最大和最小的是从哪一位开始的,同时输出最小循环节的个数. 这里简单介绍对字符串最小 ...

  7. hdu 3374 String Problem(最小表示法+最大表示法+kmp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题意:给出一个字符串问这个字符串最小表示的最小位置在哪,还有有几个最小表示的串.最大表示的位置在 ...

  8. hdu 3374 String Problem(kmp+最小表示法)

    Problem Description Give you a string with length N, you can generate N strings by left shifts. For ...

  9. HDU - 3374:String Problem (最小表示法模板题)

    Give you a string with length N, you can generate N strings by left shifts. For example let consider ...

随机推荐

  1. WPF 内部的5个窗口之 MediaContextNotificationWindow

    原文:WPF 内部的5个窗口之 MediaContextNotificationWindow 本文告诉大家在 WPF 内部的5个窗口的 MediaContextNotificationWindow 是 ...

  2. Mysql学习总结(28)——MySQL建表规范与常见问题

    一. 表设计 库名.表名.字段名必须使用小写字母,"_"分割. 库名.表名.字段名必须不超过12个字符. 库名.表名.字段名见名知意,建议使用名词而不是动词. 建议使用InnoDB ...

  3. max带来的冲突

    题目要求: /* * Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名:sum123.cpp * 作 者:林海云 * 完毕日期:20 ...

  4. C++ 数字、string 简便互转

    一.数字转为 string 类型 借用 sprintf 函数: char buffer[256]; int counter = 10; sprintf(buffer,"%04i", ...

  5. Linux线程相互排斥量--进程共享属性

    多线程中.在相互排斥量和 读写锁的 属性中.都有一个叫 进程共享属性 . 对于相互排斥量,查询和设置这个属性的方法为: pthread_mutexattr_getpshared pthread_mut ...

  6. Android 流量分析 tcpdump &amp; wireshark

    APP竞争已经白热化了,控制好自己Android应用的流量能够给用户一个良好的用户体验噢,给用户多一个不卸载的理由. Android 怎样进行流量分析?用好tcpdump & wireshar ...

  7. What's the difference between Unicode and UTF-8?

    https://stackoverflow.com/questions/3951722/whats-the-difference-between-unicode-and-utf-8 If asked ...

  8. github README.md教程

    github README.md教程 总结 github中README.md通过特殊字符标记和缩进来达到格式控制,也可以用HTML标签来实现格式控制. 教程一: Markdown 的目标是实现「易读易 ...

  9. SQL Server单表已700w+将普通表转换成分区表1

    最近项目中,某个表数据量爆发时增长,单表已700w+,读写性能急剧下降,所以考虑加入分区表以解燃眉之急,后续还是要分表分库,当然这是后话.下面简要说一下将普通表转为分区表的步骤.   一.创建文件组 ...

  10. 安卓开发--AsyncTask2

    package com.cnn.imageasyncdemo01; import android.app.Activity; import android.content.Intent; import ...