poj 2541 Binary Witch

Binary Witch
Time Limit: 1000MS Memory Limit: 65536K
   

Description

Once upon a time in the silent depths of digital forests there lived a Binary Witch. She was able to forecast weather, telling for any day in the future whether it will be rainy or sunny. 

Her magic was based on the following ancient rule: let a1, a2, ..., aN be the sequence of binary digits, where ai = 0 indicates that i-th day was rainy, and ai = 1 -- that it was sunny. To predict the weather in day N+1, consider the t-postfix a N-t+1, a N-t+2, ..., aN consisting of the last t elements. If that postfix is encountered somewhere before the position N-t+1, i.e. if there is such k <= N-t, that ak = a N-t+1, a k+1 = a N-t+2, ..., a k+t-1 = aN then the predicted value will be a k+t

If there is more than one occurrence of t-postfix, then the rightmost one (with maximal k) will be taken. So, to make a prediction, she tried t-postfixes, consequently for t = 13, 12, ..., 1, stopping after the first prediction. If neither postfix was found, she predicted rain ("0"). If prediction for more than one day is needed, it is assumed that all previous days are predicted correctly, so if first predicted value is b, then we make forecast for day N+2 based on N+1 values, where a N+1 = b. 

Because the witch was burned long ago, your task is to write a program to perform her arcane job.

 

Input

First line of input file contains two integers N (1 <= N <= 1000000) and L (1 <= L <= 1000), separated by space. Second line contains a string of N characters "0" and "1".
 

Output

Output file must contain a single string of L characters, which are forecasts for days N+1, N+2, ..., N+L.

 

Sample Input

10 7
1101110010

 

Sample Output

0100100

 

Source

Northeastern Europe 2000, Far-Eastern Subregion
 
题意:
给一个长为n的字符串s,在前面找到一个长为m(m<=13)的字符串a=后缀
在m尽量大的前提下,使找到的字符串a尽量靠后
有则在字符串s末尾添加 字符串a的最后一个字符的后一个字符
没有则在字符串s末尾添加 0
连续找L次
最后输出字符串s的最后L位
 
逆序kmp
题目要求统计的是最长后缀,将原字符串翻转,就是最长前缀
然后对于接下来的每一天做一次kmp
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn=1000000+1010;
char s[maxn],str[maxn];
int next[maxn];
char ans[1005];
int n,l;
int start=1005,len;
void getnext(char *st)
{
    int j,lm=strlen(st);
    for(int i=1;i<lm;i++)
    {
        j=next[i];
        while(j&&st[j]!=st[i]) j=next[j];
        next[i+1]= st[i]==st[j] ? j+1 : 0;
    }    
}
int kmp(char *p)
{
    int j=0,c=0,idx;
    int lm=strlen(p);
    for(int i=start+1;i<start+len;i++)
    {
        while(j&&p[j]!=str[i]) j=next[j];
        if(p[j]==str[i]) j++;
        if(j>c) { c=j; idx=i; }
        if(j==lm) return i-j;
    }
    if(c) return idx-c;
    return -1;
}
int main()
{
    char tmp[20];
    scanf("%d%d",&n,&l);
    scanf("%s",s);
    len=strlen(s);
    for(int i=0;s[i];i++) str[start+i]=s[len-1-i];
    int cnt=l,k;
    str[start+len]='\0';
    while(cnt--)
    {
        strncpy(tmp,str+start,13);
        if(len<13) tmp[len]='\0';
        else tmp[13]='\0';
        getnext(tmp);
        k=kmp(tmp);
        start--;
        len++;
        if(k==-1) str[start]='0';
        else str[start]=str[k];
    }
    for(int i=0;i<l;i++) ans[i]=str[start+l-1-i];
    ans[l]='\0';
    printf("%s",ans);
}    

 

转载于:https://www.cnblogs.com/TheRoadToTheGold/p/6955699.html

基于SSM框架的智能家政保洁预约系统,是一个旨在提高家政保洁服务预约效率和管理水平的平台。该系统通过集成现代信息技术,为家政公司、家政服务人员和消费者提供了一个便捷的在线预约和管理系统。 系统的主要功能包括: 1. **用户管理**:允许消费者注册、登录,并管理他们的个人资料和预约历史。 2. **家政人员管理**:家政服务人员可以注册并更新自己的个人信息、服务类别和服务时间。 3. **服务预约**:消费者可以浏览不同的家政服务选项,选择合适的服务人员,并在线预约服务。 4. **订单管理**:系统支持订单的创建、跟踪和管理,包括订单的确认、完成和评价。 5. **评价系统**:消费者可以在家政服务完成后对服务进行评价,帮助提高服务质量和透明度。 6. **后台管理**:管理员可以管理用户、家政人员信息、服务类别、预约订单以及处理用户反馈。 系统采用Java语言开发,使用MySQL数据库进行数据存储,通过B/S架构实现用户与服务的在线交互。系统设计考虑了不同用户角色的需求,包括管理员、家政服务人员和普通用户,每个角色都有相应的权限和功能。此外,系统还采用了软件组件化、精化体系结构、分离逻辑和数据等方法,以便于未来的系统升级和维护。 智能家政保洁预约系统通过提供一个集中的平台,不仅方便了消费者的预约和管理,也为家政服务人员提供了一个展示和推广自己服务的机会。同时,系统的后台管理功能为家政公司提供了强大的数据支持和决策辅助,有助于提高服务质量和管理效率。该系统的设计与实现,标志着家政保洁服务向现代化和网络化的转型,为管理决策和控制提供保障,是行业发展中的重要里程碑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值