当前位置:网站首页>训练总结报告
训练总结报告
2022-04-21 10:49:00 【Jinze_L】
首先先补一道今下午卡了我好长时间的水题:
新疆大学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数组的利用优化时间与空间等等,在这几次组队比赛中都出现过这些问题。
和队友大体商量了一下这几天比赛的情况,把每个人负责的部分又分工了一下,以及做题策略:开始三人以最快速度先把简单题过掉,然后稍有难度的题目两个人一起做,还要交叉检查代码,防止出现基础性错误。
还有通过这几场比赛,发现找规律的题目很多,看来要要重视规律了,不能一上来就想得很简单,应该先算一下自己的算法复杂度,然后根据题目的时间限定确定自己的做法。
版权声明
本文为[Jinze_L]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_35739903/article/details/80160019
边栏推荐
- MySQL in-depth study (30): database design specification
- GO语言反射机制
- Talk about your GC tuning ideas?
- Page navigation - declarative / programmatic navigation
- Can Jingdong Logistics, ririshun supply chain and Shunfeng find the optimal solution of logistics under the "epidemic"?
- postman设置环境变量,简单又实用
- Zsh: segmentation fault solution
- Laravel Redis的使用
- Vulnhub PRIME: 1
- Pytoch learning notes (2) examples of univariate linear regression and calculation diagram
猜你喜欢

MySQL深入学习(三十):数据库的设计规范

Pytoch learning notes (2) examples of univariate linear regression and calculation diagram

2-3. 注册selector

活动精彩预告 | 维塔士+龙智:数字化打造游戏行业「头号玩家」

A collection of econometric models and empirical Stata codes, with top publication examples

Mysql 002 DDL

Six practices of Windows operating system security attack and defense

Why programming is so difficult: starting from the deduction of stored value card

以用户体验五要素的思路,如何编写产品需求文档(PRD)

2022 information and future preparation topic 4 new online judge 2034: pruning shrubs
随机推荐
Teach you by hand: rolling bearing fault diagnosis based on deep learning
make the inifile support unicode in delphi
(SIP-1-话机注册)关于IP话机通过SIP协议注册到PBX电话交换机的全过程解析-如何看wireshark中的报文
伦敦金在哪里开户安全?
使用对数器验证简单排序
JS initial practice -- an example of dealing with the collision between a pinball and a wall
看完这篇 教你玩转渗透测试靶机vulnhub——DC9
设计一个高质量的 API 接口
【天梯赛】L3-005 垃圾箱分布(堆优化版dijkstra)
Wonderful preview of the event 𞓜 Vitas + Long Zhi: building the "number one player" in the game industry digitally
AcWing 1725. Team tic tac toe game (enumeration)
Théorie moderne du risque actuariel 07: mesure du risque
塔米狗知识|上市公司收购的基本原则
Return value usage methods in UVM and SystemVerilog
Convbert: improving Bert with span based dynamic revolution
The prospectus of quwan group is "invalid", and its TT voice has been taken off the shelf. How to achieve stable growth?
canvas 学习笔记
Summary of knapsack problem (0-1, complete, multiple knapsack problem)
AcWing 1761. Block billboard (computational geometry, intersection of two rectangles)
基于润和大禹开发板的导购系统项目方案