训练总结报告

    首先先补一道今下午卡了我好长时间的水题:

    新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)Red Rover
   One of our older Mars Rovers has nearly completed its tour of duty and is awaiting instructions
for one last mission to explore the Martian surface. The survey team has picked a route and has
entrusted you with the job of transmitting the final set of instructions to the rover. This route
is simply a sequence of moves in the cardinal directions: North, South, East, and West. These
instructions can be sent using a string of corresponding characters: N, S, E, and W. However,
receiving the signal drains the rover’s power supply, which is already dangerously low. Fortunately,
the rover’s creators built in the ability for you to optionally define a single “macro" that can be used
if the route has a lot of repetition. More concretely, to send a message with a macro, two strings are
sent. The first is over the characters {N,S,E,W,M} and the second is over {N,S,E,W}. The first
string represents a sequence of moves and calls to a macro (M), while the second string determines
what the macro expands out to. For example:
WNMWMME
EEN
is an encoding of
WNEENWEENEENE
Notice that the version with macros requires only 10 characters, whereas the original requires 13.
Given a route, determine the minimum number of characters needed to transmit it to the rover.
Input
Input consists of a single line containing a string made up of the letters N, S, E, and W representing
the route to transmit to the rover. The maximum length of the string is 100.
Input
Display the minimum number of characters needed to encode the route.
Sample Input 1 Sample Output 1
WNEENWEENEENE 10
Sample Input 2 Sample Output 2
NSEW 4
ECNA 2016 Problem E: Red Rover 9
Sample Input 3 Sample Output 3
EEEEEEEEE 6

   题意:给你一个字符串s,让你找一个子串s1,把s中所有出现过的s1都替代成字符M,问你能使字符串s变成多短,输出最短的长度 

  思路:先枚举每个原串中的子串,用kmp找出原串中不重叠子串的个数,不断维护cnt,最终找出最小值,也就是kmp+暴力

  问题:这个问题真的卡了我好久,样例总是过百分之九十几,一直在找我的解法是否有遗漏边界情况。。。最终发现我的kmp算法里getfail()函数没调用!!!。。。这都能过这么多组样例。。。好气好气

   AC代码:

   

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=111;
int f[maxn];
void getFail(char *P,int m){
    memset(f,0,sizeof(f));
    //int m =strlen(P);
    //f[0]=f[1]=0;
    for(int i=1;i<m;i++)
    {
        int j=f[i];
        while(j && P[i]!=P[j]) j=f[j];
        f[i+1] = (P[i]==P[j])?j+1:0;
    }
}
int kmp(char *T,char *P,int m)
{
    
    int cnt=0;
    int n=strlen(T);
    //int m=strlen(P);
    int j=0;
    for(int i=0;i<n;i++)
    {
        while(j && T[i]!=P[j]) j=f[j];
        if(T[i]==P[j]) j++;
        if(j==m)
        {
            cnt++;
            j=0;//kmp找不重叠子串核心
        }
    }
    return cnt;
}
 
int main()
{
    char s[maxn];
    cin>>s;
    int len =strlen(s);
    int sum= len;
    for(int i=0;i<len;i++)
    {
        for(int j=i+1;j<len;j++)
        {
            int c=0;
            char tmp[105];
            for(int k=i;k<=j;k++)
            {
                tmp[c]=s[k];
                c++;
            }
             getFail(tmp,c);
            int tt=kmp(s,tmp,c);
            int t1=c;
            sum=min(sum,len-tt*t1+tt+t1);
        }
    }
    printf("%d\n",sum);
    return 0;
}

     打完今下午的比赛,省赛前的训练暂时告一段落,从五一假期开始每天都组队打一场练习赛,理论上我们队的实力还是不弱的,但是发挥不太稳定,思路和算法知识也不差,但有时候老是被一些基础性错误卡住,总是出现思路对,但就是AC不了,最后补题的时候会发现总是一些不应该出现的错误,比如数组没清空,函数没调用,bool数组的利用优化时间与空间等等,在这几次组队比赛中都出现过这些问题。

    和队友大体商量了一下这几天比赛的情况,把每个人负责的部分又分工了一下,以及做题策略:开始三人以最快速度先把简单题过掉,然后稍有难度的题目两个人一起做,还要交叉检查代码,防止出现基础性错误。

     还有通过这几场比赛,发现找规律的题目很多,看来要要重视规律了,不能一上来就想得很简单,应该先算一下自己的算法复杂度,然后根据题目的时间限定确定自己的做法。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值