当前位置:网站首页>MUV LUV EXTRA 2019CCPC秦皇岛站J题 KMP
MUV LUV EXTRA 2019CCPC秦皇岛站J题 KMP
2022-08-09 07:01:00 【swust_fang】
题目链接
题意:意思给你俩数一个字符串,然后让你对字符串小数点后边的字符串进行处理,找个一个循环节以及对应出现的长度,
然后用a*p-b*l算得到一个最大值
那肯定循环节就想到了KMP了,然后循环长度根据样例他能从中间找一个循环节,但是都是循环到结尾的,
那一下发现他其实是从后往前找的循环节,那这个题就非常简单了
找出字符串反转一下,求KMP,从前到后枚举长度,next数组对应循环节长度,遍历一遍即可求出最大值
坑:1e7的字符出,我写的cin,意料之中的t了(t1发
ans赋初值要赋成无穷小~(wa1发!
ac代码:
//#pragma comment (linker, "/STACK:102400000,102400000")
//#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<list>
#include<time.h>
#define myself i,l,r
#define lson i<<1
#define rson i<<1|1
#define Lson i<<1,l,mid
#define Rson i<<1|1,mid+1,r
#define half (l+r)/2
#define lowbit(x) x&(-x)
#define min4(a, b, c, d) min(min(a,b),min(c,d))
#define min3(x, y, z) min(min(x,y),z)
#define max3(x, y, z) max(max(x,y),z)
#define max4(a, b, c, d) max(max(a,b),max(c,d))
typedef unsigned long long ull;
typedef long long ll;
#define pii make_pair
#define pr pair<int,int>
const int inff = 0x3f3f3f3f;
const long long inFF = 9223372036854775807;
const int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
const int mdir[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 1, -1, -1, -1};
const double eps = 1e-10;
const double PI = acos(-1.0);
const double E = 2.718281828459;
using namespace std;
const int mod=998244353;
const int maxn=1e7+5;
const int maxm=1e6+5;
char s[maxn],str[maxn];
int nex[maxn];
void get_kmp(int m)
{
int k=-1,j=0;
nex[0]=-1;
while(j<m)
{
if(k==-1||s[j]==s[k])
{
j++,k++;
nex[j]=k;
}
else k=nex[k];
}
}
int main()
{
ll a,b;
while(scanf("%lld %lld",&a,&b)!=EOF)
{
cin>>str;
int len=strlen(str);
ll ans=-inFF;
int cnt=0;
for(int i=0;i<len;i++)
{
if(str[i]=='.')
{
for(int j=len-1;j>i;j--) s[cnt++]=str[j];
break;
}
}
get_kmp(cnt);
for(int i=1;i<=cnt;i++)
ans=max(ans,a*i-b*(i-nex[i]));
printf("%lld\n",ans);
}
}
边栏推荐
- Error: flask: TypeError: 'function' object is not iterable
- P6阿里机试题之2020 斐波那契数
- 按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
- Simple to use Lambda expressions
- 当酷雷曼VR直播遇上视频号,会摩擦出怎样的火花?
- Use baidu EasyDL intelligent bin
- db.sqlite3 has no "as Data Source" workaround
- 【Oracle 11g】Redhat 6.5 安装 Oracle11g
- ByteDance Interview Questions: Mirror Binary Tree 2020
- 日期处理,字符串日期格式转换
猜你喜欢

Output method of list string print(*a) print(““.join(str(c) for c in a) )

leetcode 之 70 爬楼梯问题 (斐波那契数)

Search 1688 product interface by image (item_search_img-search 1688 product by image (Politao interface) code docking tutorial

XILINX K7 FPGA+RK3399 PCIE驱动调试

Inception V3 闭眼检测

INSTALL_RPATH and BUILD_RPATH problem in CMake

图论,二叉树,dfs,bfs,dp,最短路专题

【Oracle 11g】Redhat 6.5 安装 Oracle11g

Import the pycharm environment package into another environment

Mysql实操
随机推荐
【修电脑】系统重装但IP不变后VScode Remote SSH连接失败解决
DSP+ARM+FPGA高速PCIE/千兆网口信号仿真介绍
2017.10.26模拟 b energy
Service
codeforces Valera and Elections (这思维题是做不明白了)
买口罩(0-1背包)
什么是分布式事务
RK3568商显版开源鸿蒙板卡产品解决方案
分布式id 生成器实现
MongDb的查询方式
io.lettuce.core。RedisCommandTimeoutException命令超时
物理层课后作业
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS重大开销和将disab补充道
XxlJobConfig distributed timer task management XxlJob configuration class, replace
SIGINT,SIGKILL,SIGTERM信号区别,各类信号总结
我入职阿里后,才知道原来简历这么写
金九银十即将到来,求职套路多,面试指南我来分享~
MongDb query method
cut命令的使用实例
install flask