日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

39行代码AC_HDU-6740 2019CCPC秦皇岛 J MUV LUV EXTRA(KMP变形)

發(fā)布時間:2024/2/28 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 39行代码AC_HDU-6740 2019CCPC秦皇岛 J MUV LUV EXTRA(KMP变形) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

勵志用少的代碼做高效表達(dá)


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?la * p - b * la?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.


解題思路

如果有對KMP還不懂的同學(xué)——>KMP算法_圖示分析+解析+例題

這個題很巧妙的利用了 KMP

我們需要反過來求kmp得next數(shù)組,枚舉前綴,那么i就是循環(huán)節(jié)出現(xiàn)的總長度,而i-next[i]就是循環(huán)節(jié)長度。


代碼展示

#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll INF=1e18; ll a,b,res; int i,j,k; char s[10000010], s1[10000010]; int Next[10000010];void getnext(char s[],int Next[]) {int q,k;int len=strlen(s);Next[0] = 0;for (q = 1,k = 0; q < len; ++q) {while(k>0 && s[q]!=s[k]) k = Next[k-1];if (s[q] == s[k]) k++;Next[q] = k;} }int main() {while(cin>>a>>b) {memset(Next,0,sizeof Next);cin>>s1;int len1=strlen(s1);int len=0;for(i=len1-1; i>=0; i--) {if(s1[i]=='.') break;s[len1-i-1]=s1[i];len++;}getnext(s,Next);ll ans=-INF;for(i=0; i<len; i++) {res=a*(i+1)-b*(i+1-Next[i]); //核心代碼if(res>ans) ans=res;}cout << ans << '\n';} return 0; }

總結(jié)

以上是生活随笔為你收集整理的39行代码AC_HDU-6740 2019CCPC秦皇岛 J MUV LUV EXTRA(KMP变形)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 禁片天堂 | 久久久久久av | 爆操老女人 | 国产乱一区二区三区 | 操操综合 | 中文天堂 | 欧美日韩在线成人 | 国产成人三级一区二区在线观看一 | 久久久久久五月天 | 女同性恋一区二区三区 | a网址 | 国产精品一亚洲av日韩av欧 | 激情综合激情 | 漂亮少妇高潮午夜精品 | 亚洲 另类 春色 国产 | 天美视频在线观看 | 欧美久久精品一级黑人c片 1000部多毛熟女毛茸茸 | 久草免费在线播放 | 久久大奶 | 老色批av | 日韩欧美在线观看一区二区 | 亚洲第一在线视频 | 免费在线观看黄色网址 | 色无极亚洲| 四虎三级| 黄色高清网站 | 精品人伦一区二区三区蜜桃网站 | 精品国产一区二区三区无码 | www.蜜桃av | av片网| 免费网站黄色 | 国产免费一区二区三区网站免费 | 黄色变态网站 | 奇米视频在线 | 白洁av| 久久亚洲影院 | 96久久精品 | 日日夜夜噜| 精品黄色 | 九九热精品在线 | 水蜜桃影库 | 欧美激情3p| 欧美老肥妇做.爰bbww视频 | 草久久久久 | 国产无遮挡免费观看视频网站 | 久久99久久99精品免观看软件 | 高清国产mv在线观看 | 午夜在线观看视频网站 | 亚洲免费网站 | 国产美女激情视频 | 极品粉嫩国产18尤物 | 青青久久久 | 国产91精品久久久久久久网曝门 | 国产成人手机视频 | 久久字幕 | 9.1成人免费看片 | 欧美色图综合网 | 爆操白虎逼| 日韩欧美国产精品综合嫩v 国产小毛片 | 精品久久无码中文字幕 | 国产综合福利 | 国产福利在线视频观看 | 日韩和欧美一区二区 | 国产毛片基地 | 日日干日日爽 | 涩涩视频在线观看免费 | 中文字幕视频网站 | 最新中文字幕视频 | 欧美午夜精品一区二区三区 | 欧美视频一区二区三区在线观看 | 岛国精品 | 亚洲欧美综合网 | 浪漫樱花在线观看高清动漫 | 日韩经典中文字幕 | 懂色av | 欧美性受xxxx黑人xyx性爽 | 久久精品99国产精 | 爱情岛亚洲论坛入口福利 | 交专区videossex非洲 | 99久久久国产精品 | 午夜剧场福利 | 国产精品一区三区 | 欧美日韩电影一区二区 | 免费人成在线观看网站 | 蜜桃视频无码区在线观看 | 国产欧美一区二区三区在线看蜜臂 | 极品在线观看 | 久久综合九色 | cekc老妇女cea0 | 黄色网页免费观看 | 色导航 | 国产高清视频在线观看 | 下面一进一出好爽视频 | 婷婷深爱五月 | 欧美在线观看成人 | 222aaa| 一区二区三区在线 | 四虎在线免费视频 | 国产成人av影院 |