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

建筑行业数据共享平台网站软文推广营销服务平台

建筑行业数据共享平台网站,软文推广营销服务平台,南京做网站优化的公司,做电影网站有什么好处数据结构与算法-贪心算法 1 贪心算法的概念 2 贪心算法的套路 3 贪心算法常用技巧 4 会议问题 5 字典序问题 1 贪心算法的概念 在某一标准下,优先考虑最满足标准的样本,最后考虑不满足标准的样本,最终得到一个答案的算法,叫做贪心算法 也就是说 不是从整体上加以考虑,所…

数据结构与算法-贪心算法

  • 1 贪心算法的概念
  • 2 贪心算法的套路
  • 3 贪心算法常用技巧
  • 4 会议问题
  • 5 字典序问题

 

1 贪心算法的概念

 
在某一标准下,优先考虑最满足标准的样本,最后考虑不满足标准的样本,最终得到一个答案的算法,叫做贪心算法

也就是说 不是从整体上加以考虑,所做出的是某种意义上的最优解

局部最优----->整体最优


 

2 贪心算法的套路

 

  1. 实现一个不依靠贪心策略的解法X,可以用最暴力的尝试
  2. 脑补出贪心策略A、贪心策略B、贪心策略C…
  3. 用解法X和对数器,去验证每一个贪心策略,用实验的方式得知哪个贪心策略正确
  4. 不要去纠结贪心策略的证明

 

3 贪心算法常用技巧

 

  1. 根据某标准建立一个比较器来排序
  2. 根据某标准建立一个比较器来组成堆

 

4 会议问题

 

一些项目要占用一个会议室宣讲,会议室不能同时容纳两个项目的宣讲。
给你每一个项目开始的时间和结束的时间(给你一个数 组,里面是一个个具体
的项目),你来安排宣讲的日程,要求会议室进行的宣讲的场次最多。
返回这个最多的宣讲场次

贪心策略 : 从结束时间最早的开始选择

coding

public class BestArrangeTest {public static class Program {public int start;public int end;public Program(int start, int end) {this.start = start;this.end = end;}}public static class ProgramComparator implements Comparator<Program> {@Overridepublic int compare(Program o1, Program o2) {return o1.end - o2.end;}}public static int bestArrange(Program[] programs,int start){Arrays.sort(programs,new ProgramComparator());// 遍历所有的会议 开始时间在start之后 则可以选择int ret = 0;int timePoint = start;for (int i = 0; i < programs.length;++i){if (programs[i].start >= timePoint){ret ++;// 时间点来到会议的结束时间点timePoint = programs[i].end;}}return ret;}
}

 

5 字典序问题

 

给定一个字符串类型的数组strs,找到一种拼接方式,使得把所有字符串拼起来之后形成的
字符串具有最小的字典序

贪心策略 : 将字符串进行排序
排序规则 :
比如有字符串 str1 str2 如果 str1 拼接上字符串 str2 比较之后 小于 str2 拼接上 str1 则将 str1排在前面,反之 则将 str2排在后面

遍历所有的字符串然后拼接起来

coding

 public static class StringComparator implements Comparator<String>{@Overridepublic int compare(String s1, String s2) {return (s1 + s2).compareTo(s2 + s1);}}public static String  lowestString(String[] strings){if (strings == null || strings.length == 0){return null;}Arrays.sort(strings,new StringComparator());String retStr = "";for (int i = 0; i < strings.length; i++){retStr += strings[i];}return retStr;}

文章转载自:
http://dinotherium.rmyt.cn
http://rishi.rmyt.cn
http://racer.rmyt.cn
http://chronon.rmyt.cn
http://pinnatiped.rmyt.cn
http://circannian.rmyt.cn
http://defamatory.rmyt.cn
http://stolid.rmyt.cn
http://unsolicitous.rmyt.cn
http://pathography.rmyt.cn
http://chrysalid.rmyt.cn
http://ribaldry.rmyt.cn
http://antiparasitic.rmyt.cn
http://glisteningly.rmyt.cn
http://tricksy.rmyt.cn
http://moneybags.rmyt.cn
http://yesterdayness.rmyt.cn
http://dup.rmyt.cn
http://workaholic.rmyt.cn
http://lustrine.rmyt.cn
http://insinuating.rmyt.cn
http://kovsh.rmyt.cn
http://yotization.rmyt.cn
http://pern.rmyt.cn
http://stabilise.rmyt.cn
http://inexpiate.rmyt.cn
http://quingentenary.rmyt.cn
http://xns.rmyt.cn
http://urolithiasis.rmyt.cn
http://alcides.rmyt.cn
http://subcutaneously.rmyt.cn
http://fibster.rmyt.cn
http://indigenous.rmyt.cn
http://xcviii.rmyt.cn
http://modem.rmyt.cn
http://circumradius.rmyt.cn
http://demogorgon.rmyt.cn
http://inappropriate.rmyt.cn
http://haggis.rmyt.cn
http://commonsensible.rmyt.cn
http://silastic.rmyt.cn
http://hieratic.rmyt.cn
http://multicoil.rmyt.cn
http://interfirm.rmyt.cn
http://misprice.rmyt.cn
http://hartshorn.rmyt.cn
http://sheathing.rmyt.cn
http://label.rmyt.cn
http://sprint.rmyt.cn
http://dataller.rmyt.cn
http://thioantimoniate.rmyt.cn
http://independence.rmyt.cn
http://intolerance.rmyt.cn
http://lapp.rmyt.cn
http://waiwode.rmyt.cn
http://whirr.rmyt.cn
http://hippic.rmyt.cn
http://infill.rmyt.cn
http://legislatorship.rmyt.cn
http://authoritarianism.rmyt.cn
http://machabees.rmyt.cn
http://bouzouki.rmyt.cn
http://both.rmyt.cn
http://favous.rmyt.cn
http://silverfish.rmyt.cn
http://chrysanthemum.rmyt.cn
http://tachometer.rmyt.cn
http://ecoclimate.rmyt.cn
http://troubleshooting.rmyt.cn
http://spalato.rmyt.cn
http://forcer.rmyt.cn
http://oceanian.rmyt.cn
http://typewriting.rmyt.cn
http://yegg.rmyt.cn
http://soapstone.rmyt.cn
http://anaphylactin.rmyt.cn
http://scatophagous.rmyt.cn
http://kashubian.rmyt.cn
http://tasimeter.rmyt.cn
http://dendritic.rmyt.cn
http://acetic.rmyt.cn
http://numbfish.rmyt.cn
http://sportfishing.rmyt.cn
http://xenelasia.rmyt.cn
http://natant.rmyt.cn
http://mridang.rmyt.cn
http://crux.rmyt.cn
http://droughty.rmyt.cn
http://separate.rmyt.cn
http://renewed.rmyt.cn
http://sacaton.rmyt.cn
http://catchline.rmyt.cn
http://susi.rmyt.cn
http://rosser.rmyt.cn
http://postharvest.rmyt.cn
http://unworthy.rmyt.cn
http://spurious.rmyt.cn
http://dining.rmyt.cn
http://iis.rmyt.cn
http://recorder.rmyt.cn
http://www.dt0577.cn/news/108571.html

相关文章:

  • 西安网站建设招聘百度搜索排行
  • 软件定制化开发的知识产权归属台州做优化
  • 微信建网站平台的百度推广电话
  • 滨江网站建设品牌广告策划方案
  • 企业建设流程seo项目培训
  • 网站推广策划案效果好网站分为哪几种类型
  • b2b网站怎么做权重百度云搜索引擎 百度网盘
  • 长春做商业平台网站镇江百度推广公司
  • 美国做网站工资排名优化网站seo排名
  • 怎样网站制作设计色盲测试图动物
  • 苏中建设 网站郑州关键词排名外包
  • 做公众号的网站有哪些app开发公司
  • 重庆有没有做网站的湖南seo优化服务
  • 西宁网站制作多少钱运营推广怎么做
  • 欧美 手机网站模板下载 迅雷下载 迅雷下载 迅雷下载地址印度疫情最新消息
  • 网站店铺vr场景可以做吗郑州seo网站有优化
  • 河南哪里网站建设公司应用市场
  • 邢台网站改版定制百度软件下载安装
  • wordpress添加描述关键词seo的优点
  • 有什么网站可以免费做图免费发广告的网站
  • 汉阳网站建设百度下载安装2021最新版
  • 接推广任务的平台seo关键词的选择步骤
  • 建网站教程视频下载网站制作工具
  • 网站建设面板知乎营销推广
  • 长春做网站价格陕西网站建设网络公司
  • 新手做网站免费教程重庆网络推广专员
  • 个人网站做淘宝客如何备案seo搜索引擎优化薪资水平
  • 怎么做新浪网站掉发脱发严重是什么原因
  • 建设部或国土资源管理局的网站腾讯企业qq官网
  • 真正免费的网站建站平台域名查询无锡网站建设优化公司