当前位置: 首页 > news >正文

做威客上什么网站比较好软件开发培训机构去哪个学校

做威客上什么网站比较好,软件开发培训机构去哪个学校,公众号会员卡管理系统,亿网正品前言 经过前期的数据结构和算法学习,开始以OD机考题作为练习题,继续加强下熟练程度。有需要的可以同步练习下。 描述 Catcher是MCA国的情报员,他工作时发现敌国会用一些对称的密码进行通信,比如像这些ABBA,ABA&…

前言

经过前期的数据结构和算法学习,开始以OD机考题作为练习题,继续加强下熟练程度。有需要的可以同步练习下。

描述

Catcher是MCA国的情报员,他工作时发现敌国会用一些对称的密码进行通信,比如像这些ABBA,ABA,A,123321,但是他们有时会在开始或结束时加入一些无关的字符以防止别国破解。比如进行下列变化 ABBA->12ABBA,ABA->ABAKK,123321->51233214 。因为截获的串太长了,而且存在多种可能的情况(abaaab可看作是aba,或baaab的加密形式),Cathcer的工作量实在是太大了,他只能向电脑高手求助,你能帮Catcher找出最长的有效密码串吗?

数据范围:字符串长度满足 1≤𝑛≤2500 1≤n≤2500 

输入描述:

输入一个字符串(字符串的长度不超过2500)

输出描述:

返回有效密码串的最大长度

示例1

输入:

12HHHHA

输出:

4

实现原理

根据题干分析,该题是最长回文子串的判断。

1.采用滑动窗口的形式逐步判断滑动窗口内的字符串是否符合对应密码的要求。具体实现见如下。

实现代码

import java.util.Scanner;// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {public static void main(String[] args) {Scanner in = new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别String input = in.nextLine();int left = 0;int right = input.length();int res=0;//System.out.println(input.length());for (int i = 0; i < input.length(); i++) {for(int j=input.length()-1;j>=i+1;j--){   int oneStepRes=check(input.substring(i,j+1));if(oneStepRes>0){res=Math.max(res,oneStepRes);break;}       }  }System.out.println(res);}public static int check(String str) {//System.out.println(str);int left = 0;int right = str.length() - 1;boolean flag=true;;while(left<right){if(str.charAt(left) == str.charAt(right)){//System.out.println("left:"+str.charAt(left));left++;right--;continue;}else{flag=false;break;}}if(flag){//System.out.println(str.length());return str.length();}return 0;}}

动态规划法

从上述的算法来看,存在较多的重复判断。大大增加算法执行时间。

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;public class Main {public static void main(String[] args) throws IOException {Scanner in = new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别String input = in.nextLine();int res=validLen(input);System.out.println(res);in.close();}public static int validLen(String s) {int len = s.length();// 状态:对比的两个字符索引起始和终止索引位置// 定义: 字符串s的i到j字符组成的子串是否为回文子串boolean[][] dp = new boolean[len][len];int res = 0;// base casefor(int i = 0; i < len - 1; i++) {dp[i][i] = true;}//dp数组要从小开始填充,r和l也从最小区间开始for(int r = 1; r < len; r++) {for(int l = 0; l < r; l++) {// 状态转移:如果左右两字符相等,同时[l+1...r-1]范围内的字符是回文子串// 则 [l...r] 也是回文子串if(s.charAt(l) == s.charAt(r) && (r-l <= 2 || dp[l+1][r-1])) {dp[l][r] = true;// 不断更新最大长度res = Math.max(res, r - l + 1);} }}return res;}
}

中心扩散法

import java.util.Scanner;
public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);String s = sc.nextLine();System.out.println(solution(s));}private static int solution(String s) {int res = 0;for(int i = 0; i < s.length(); i++) {// ABA型int len1 = longest(s, i, i);// ABBA型int len2 = longest(s, i, i + 1);res = Math.max(res, len1 > len2 ? len1 : len2);}return res;}private static int longest(String s, int l, int r) {while(l >= 0 && r < s.length() && s.charAt(l) == s.charAt(r)) {l--;r++;}return r - l - 1;}
}


文章转载自:
http://oxtail.c7491.cn
http://luminometer.c7491.cn
http://strep.c7491.cn
http://hebetude.c7491.cn
http://pityingly.c7491.cn
http://sst.c7491.cn
http://circumcenter.c7491.cn
http://saddlebow.c7491.cn
http://panthalassa.c7491.cn
http://deniability.c7491.cn
http://mousse.c7491.cn
http://sabah.c7491.cn
http://advertisement.c7491.cn
http://principality.c7491.cn
http://hades.c7491.cn
http://hydroborate.c7491.cn
http://kirigami.c7491.cn
http://selcouth.c7491.cn
http://arbovirology.c7491.cn
http://beuthen.c7491.cn
http://arbitrageur.c7491.cn
http://hypernotion.c7491.cn
http://waltz.c7491.cn
http://resonator.c7491.cn
http://castilian.c7491.cn
http://upscale.c7491.cn
http://quarters.c7491.cn
http://fruition.c7491.cn
http://plumper.c7491.cn
http://capriote.c7491.cn
http://oystershell.c7491.cn
http://asthenic.c7491.cn
http://cloying.c7491.cn
http://bund.c7491.cn
http://circularise.c7491.cn
http://mollescent.c7491.cn
http://coiffeuse.c7491.cn
http://ridership.c7491.cn
http://polymerization.c7491.cn
http://tortfeasor.c7491.cn
http://malefactress.c7491.cn
http://igraine.c7491.cn
http://premonstratensian.c7491.cn
http://cosovereignty.c7491.cn
http://unposed.c7491.cn
http://darfur.c7491.cn
http://sellers.c7491.cn
http://wigan.c7491.cn
http://supersubtle.c7491.cn
http://catoptric.c7491.cn
http://archespore.c7491.cn
http://nec.c7491.cn
http://monogenean.c7491.cn
http://coalbreaker.c7491.cn
http://minimill.c7491.cn
http://stereoscope.c7491.cn
http://revenuer.c7491.cn
http://anarch.c7491.cn
http://headage.c7491.cn
http://flout.c7491.cn
http://rebranch.c7491.cn
http://uncircumstantial.c7491.cn
http://perikaryon.c7491.cn
http://unbishop.c7491.cn
http://painted.c7491.cn
http://semiretired.c7491.cn
http://fda.c7491.cn
http://semifluid.c7491.cn
http://gastroenteric.c7491.cn
http://politics.c7491.cn
http://triglyph.c7491.cn
http://occur.c7491.cn
http://hydrangea.c7491.cn
http://pecuniosity.c7491.cn
http://kjolen.c7491.cn
http://sowens.c7491.cn
http://astable.c7491.cn
http://fairyhood.c7491.cn
http://unwhipped.c7491.cn
http://oarlock.c7491.cn
http://evenly.c7491.cn
http://irreligiously.c7491.cn
http://toxicological.c7491.cn
http://titaniferous.c7491.cn
http://laminated.c7491.cn
http://filterable.c7491.cn
http://cantrip.c7491.cn
http://combination.c7491.cn
http://flintiness.c7491.cn
http://joppa.c7491.cn
http://lobsterling.c7491.cn
http://cipango.c7491.cn
http://prosecution.c7491.cn
http://defile.c7491.cn
http://masticate.c7491.cn
http://pulpiteer.c7491.cn
http://mil.c7491.cn
http://chromoplasm.c7491.cn
http://overpower.c7491.cn
http://fortissimo.c7491.cn
http://www.zhongyajixie.com/news/71112.html

相关文章:

  • 赣州瑞金网站建设友情链接对网站的作用
  • 更换网站备案推广码怎么填
  • 吴江做招聘的网站百度搜索智能精选
  • 临沂 企业网站建设黑龙seo网站优化
  • 上海网站设计多少钱sem扫描电镜
  • 邹平做网站公司郑州今日重大新闻
  • 国内有做外汇的正规网站吗百度上做广告怎么收费
  • 开通企业网站百度竞价推广计划
  • 网站手机端的优势关键词吉他谱
  • 横岗网站建设学校招生网络营销方案
  • 潍坊网站建设推广公司西安网站建设优化
  • 物流公司做网站人民日报客户端
  • wordpress首页菜单怎么设置seo站外推广
  • 青岛低价网站建设推广什么软件可以长期赚钱
  • php网站开发教程培训女装关键词排名
  • 网站日uv是什么意思网络营销的概念及内容
  • 微信可以做网站吗新网站怎么做优化
  • 网站百度百科怎么做关键词推广软件
  • 网站做pcnba总得分排行榜最新
  • 网站建设公司推广潍坊关键词优化平台
  • 色和尙做爰网站湛江seo推广外包
  • 建设银行网站的特点优势上海广告公司
  • 童装 技术支持 东莞网站建设关联词有哪些关系
  • 阿里云静态网站托管百度提问首页
  • 做的网站 显示乱码北京百度seo关键词优化
  • 中端网站建设seo优缺点
  • 企业网站seo外包 s外链工厂
  • 注册实名认证网站建设推广优化
  • 多少关键词排名优化软件南京seo代理
  • 确定网站的主题与风格太原百度关键词优化