MUV LUV EXTRA

Time Limit: 2000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 134    Accepted Submission(s): 49

Problem Description
One day, Kagami Sumika is stuck in a math problem aiming at calculating the length of a line segment with given statements and constraints. Since Sumika has no idea about it, she takes out a ruler and starts to measure the length. Unfortunately, the answer is an infinite decimal and she only got the first some digits of the answer from the ruler.
Sumika guesses that the answer is a rational number, which means that there exists two integers p, q that the answer equals qp. In this situation, the answer can be expressed as an infinte repeated decimal. For example, 12 = 0.500 ... , 13 = 0.333 .... , 910= 0.8999 ... ,3635= 1.0285714285714 ... .Sumika wants to guess the original number from the digits she got. Note that a number may has more than one way to be expressed such as 1.000 ... = 0.999 ... . Sumika won’t transform the digits she got to another form when guessing the original number.
Furthermore, Sumika relizes that for a repeating part, either too long or the appeared length too short will make the result unreliable. For example, if the decimal she measured is 1.0285714285714, it is obviously unreliable that the repeating part is “0285714285714”, since it is too long, or “428571”, since the appeared length is too short, which equals 7, the length of “4285714”. In this case, the best guess is “285714”, whose length is 6 and the appeared length is 12. So formally, she defines the reliability value of a repeating part, whose length is l and the appeared length is p, as the following formula:
a * p - b * l
Where a and b are given parameters.
Last but not least, you can ignore the integer parts of the decimal. It is just for restoring the scene. And the repeating part you guess should be completely repeated at least once and is still repeating at the end currently.
Please help Sumika determine the maximum reliability value among all repeating parts.
 
Input
The first line contains two positive integers a, b (1 ≤ a, b ≤ 109), denoting the parameters.
The next line contains a string s (1 ≤ |s| ≤ 107) in decimal form, denoting the first some digits of the accurate result.
It is guaranteed that there is exactly one decimal point in s and s is a legal non-negative decimal without leading "-"(the minus sign).
 
Output
Output a single line containing an integer, denoting the maximum reliability value.
 
Sample Input
5 3
1.1020
2 1
12.1212
 
Sample Output
9
6
 
Source
 

题解:

是个套了外壳的字符串题,求得是后缀的循环节长度和循环节出现的总长度(包括不完整循环节),显然我们反过来求kmp得next数组,枚举前缀,那么i就是循环节出现的总长度,而i-next[i]就是循环节长度。

参考代码:

#include<bits/stdc++.h>
#define maxl 10000010
using namespace std; const long long inf=1ll<<;
long long a,b,ans;
int slen,tlen;
int nxt[maxl];
char s[maxl],t[maxl]; inline void mainwork()
{
ans=a-b;
int j=;nxt[]=;
for(int i=;i<=tlen;i++)
{
while((j && t[j+]!=t[i]) || (j==tlen))
j=nxt[j];
if(t[j+]==t[i] && j+<=tlen)
j++;
nxt[i]=j;ans=max(ans,a*i-b*(i-nxt[i]));
}
} int main()
{
while(~scanf("%lld%lld",&a,&b))
{
scanf("%s",s+);
slen=strlen(s+);tlen=;
for(int i=slen;i>=;i--)
if(s[i]=='.')
break;
else
t[++tlen]=s[i];
mainwork();
printf("%lld\n",ans);
}
return ;
}

2019CCPC秦皇岛 J MUV LUV EXTRA(KMP)的更多相关文章

  1. 2019CCPC秦皇岛 K MUV LUV UNLIMITED(博弈)

    MUV LUV UNLIMITED Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  2. HDU6740 2019CCPC秦皇岛赛区 J. MUV LUV EXTRA

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6740思路:求小数部分后k位的真前后缀 倒着kmp就好 #include<bits/stdc++.h& ...

  3. 【2019 CCPC 秦皇岛】J - MUV LUV EXTRA

    原题: 题意: 给你两个整数a和b,再给你一个正小数,整数部分忽略不计,只考虑小数部分的循环节,对于所有可能的循环节,令其长度为l,在小数部分循环出现的长度为p,最后一个循环节允许不完整,但是缺少的部 ...

  4. 2019-ccpc秦皇岛现场赛

    https://www.cnblogs.com/31415926535x/p/11625462.html 昨天和队友模拟了下今年秦皇岛的区域赛,,,(我全程在演 题目链接 D - Decimal 签到 ...

  5. 2019CCPC秦皇岛赛区(重现赛)- J

    链接: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=872 题意: 鉴纯夏是一名成绩不太好的高中生. ...

  6. 2019CCPC秦皇岛自我反省&部分题解

    练了一年半了,第一次打CCPC,险些把队友坑了打铁,最后也是3题危险捡了块铜. 非常水的点双连通,我居然不相信自己去相信板子,唉,结果整来整去,本来半个小时能出的题,整到了3个小时,大失误呀,不然就可 ...

  7. 2019CCPC秦皇岛 E题 Escape(网络流)

    Escape Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  8. 2019CCPC秦皇岛I题 Invoker(DP)

    Invoker Time Limit: 15000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  9. 2019CCPC 秦皇岛 E.Escape

    传送门 题意: 给出一个\(n*m\)的迷宫,有\(a\)个入口,\(b\)个出口. 现在有\(a\)个机器人都从入口出发,一开始方向默认为下,你可以选在在一些格子上面放置一个转向器,转向器有四种: ...

随机推荐

  1. python函数的基本语法<一>

    函数: 一次定义,多次调用,函数可以变相看成变量函数的阶段: 1.定义阶段 2调用阶段 形参和实参: 定义阶段的参数叫形参,调用阶段的参数叫实参 函数的几种基本用法: #多变量 def test(na ...

  2. IO类

    Java的IO体系分为Input/Output和Reader/Writer两类,区别在于Reader/Writer在读写文本时能自动转换内码.基本上,所有的IO类多是配对的,即有XXXInput,就有 ...

  3. [SD卡] FPGA笔记之SD卡

    1.数据怎么存进去的? 其中的sd_miso就是接收的1位数据,n个时钟下就收到n个数据,比如n=21. 2.如何做到先发送高位?

  4. nyoj 599-奋斗的小蜗牛 (double ceil(); (temp - 1) / 5)

    599-奋斗的小蜗牛 内存限制:64MB 时间限制:1000ms 特判: No 通过数:0 提交数:96 难度:1 题目描述: 传说中能站在金字塔顶的只有两种动物,一种是鹰,一种是蜗牛.一只小蜗牛听了 ...

  5. nyoj 243-交换输出 (swap)

    243-交换输出 内存限制:64MB 时间限制:3000ms 特判: No 通过数:16 提交数:39 难度:1 题目描述: 输入n(n<100)个数,找出其中最小的数,将它与最前面的数交换后输 ...

  6. 0xe7f001f0!?NDK调试过程,无故抛出SIGSEGV。

    arm调试过程,如果抛一个SIGSEGV,地址在 0xe7f001f0 附近,原因居然是因为我在调试.当我使用n指令跳到下一行代码时,往往变成了continue指令一样地执行.还不确定地抛出SIGSE ...

  7. 使用shiro做权限管理的学习笔记整理

    Shiro权限管理 参考:https://www.cnblogs.com/jpfss/p/8352031.html Shiro解决的问题 授权和鉴别的问题:Authenrization(授权) Aut ...

  8. Nvm安装步骤

    下载地址 https://github.com/coreybutler/nvm-windows/releases 解压压缩包,后是一个.exe结尾的安装文件,双击安装, 选择安装位置,如下图: 设置n ...

  9. PHP创建对象的6种方式

    创建对象实例: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...

  10. 2019-9-9:渗透测试,基础学习,windows基础命令,笔记

    windows系统基础命令学习 1,命令提示符界面进入方法 方法一: 某分区按住shift,右键单击选择在此处打开windows powershell,进入之后输入cmd 方法二:标题栏输入 方法三: ...