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

移动网站 拉新近三天发生的重要新闻

移动网站 拉新,近三天发生的重要新闻,网站建设公司河南,网站模板制作与安装教程视频教程贪心算法是一种简单而直观的算法思想,它在每一步选择中都采取在当前状态下最优的选择,以期望最终得到全局最优解。贪心算法通常适用于一些具有最优子结构的问题,即问题的最优解可以通过一系列局部最优解的选择得到。 贪心算法的基本思路是&a…

贪心算法是一种简单而直观的算法思想,它在每一步选择中都采取在当前状态下最优的选择,以期望最终得到全局最优解。贪心算法通常适用于一些具有最优子结构的问题,即问题的最优解可以通过一系列局部最优解的选择得到。

贪心算法的基本思路是,每一步都选择当前状态下的局部最优解,并把它添加到当前解中。然后,根据已经做出的选择,对剩下的子问题进行求解。这个过程持续进行,直到得到全局最优解。

然而,贪心算法并不是适用于所有问题的。在一些情况下,贪心算法可能会得到次优解或者不正确的解。这是因为贪心算法在每一步都做出局部最优选择,并没有考虑到该选择对之后步骤的影响。

综上所述,贪心算法是一种简单而直观的算法思想,可以用来解决一些具有最优子结构的问题。

目录

贪心算法(找零问题)

背包问题

分数背包

数字拼接问题

常识:时间戳

活动选择问题


贪心算法(找零问题)

# 贪心算法
t = [100, 50, 20, 5, 1]
# 找零
def chang_money(n):m = [[0] for _ in range(len(t))]for i,money in enumerate(t):m[i] = n // moneyn = n % moneyreturn m,n
​
print(chang_money(376))

([3, 1, 1, 1, 1], 0)

背包问题

答:0-1背包问题不能使用贪心算法解决,

分数背包问题可以。

分数背包

先拿单位重量最值钱的物品(算法思想)

# 分数背包
# 贪心算法思想
goods = [(60,10),(100,20),(120,30)]     #(价值,重量)
​
def fenshu_bag(goods,w):goods.sort(key=lambda x:x[0]//x[1],reverse=True)        # 按照贪心算法进行拿取print(goods)m = [0 for _ in range(len(goods))]      # 记录排好价值的物品拿多少total_val = 0                           # 记录最终总价值for i,(prize,weight) in enumerate(goods):              if weight <= w:                     # 如果背包能放得下m[i] = 1total_val += prizew -= weightelse:                               # 背包放不下m[i] = w / weighttotal_val += m[i] * prizew = 0breakreturn total_val,m
print(fenshu_bag(goods,50))

[(60, 10), (100, 20), (120, 30)] (240.0, [1, 1, 0.6666666666666666])

数字拼接问题

 
# 数字拼接问题
from functools import cmp_to_key
​
li = [32, 94, 128, 1286, 6, 71]
​
def xy_cmp(x,y):if x+y < y+x:       # 说明y应该排在x的前面return 1elif x+y > y+x:return -1else:return 0
​
def number_join(li):li = list(map(str,li))li.sort(key=cmp_to_key(xy_cmp))     # 类似于冒泡 比较的是unicode编码return "".join(li)
​
print(number_join(li))

94716321286128

常识:时间戳

时间戳(Timestamp)是一种表示某个特定时刻的数字标识,它记录了从一个特定起始时间点到指定时刻所经过的秒数(或者毫秒数、微秒数 ,具体精度因系统和应用而异)。常见的时间戳有以下两种类型:

  • Unix 时间戳:Unix 系统广泛使用的时间表示方法,它以 1970 年 1 月 1 日 00:00:00 UTC(协调世界时)作为起始时间点,记录到指定时刻历经的秒数 。例如,Unix 时间戳为 1690579200 对应的北京时间是 2023 年 7 月 29 日 00:00:00,因为从 1970 年 1 月 1 日 00:00:00 UTC 到这个时刻,恰好经过了 1690579200 秒。在 Python 中,可以使用time模块来获取和处理 Unix 时间戳:

import time
​
# 获取当前Unix时间戳
current_timestamp = time.time()  
print(current_timestamp)

活动选择问题

# 活动选择问题
activities = [(1,4),(3,5),(0,6),(5,7),(3,9),(6,10),(8,11),(8,12),(2,14),(12,16)]
activities.sort(key=lambda x:x[1])      # 按照结束时间升序排列
​
def activities_selection(a):res = [a[0]]for i in range(1, len(a)):if a[i][0] >= res[-1][1]:       # 活动的开始时间大于等于前一个活动的结束时间可以进行res.append(a[i])return res
​
print(activities_selection(activities))

[(1, 4), (5, 7), (8, 11), (12, 16)]


文章转载自:
http://comtesse.tsnq.cn
http://vidicon.tsnq.cn
http://condensability.tsnq.cn
http://infidelic.tsnq.cn
http://productile.tsnq.cn
http://gentle.tsnq.cn
http://prosodiac.tsnq.cn
http://appetent.tsnq.cn
http://ijsselmee.tsnq.cn
http://vitrectomy.tsnq.cn
http://carrefour.tsnq.cn
http://geopolitical.tsnq.cn
http://unremitted.tsnq.cn
http://unacted.tsnq.cn
http://superbike.tsnq.cn
http://weeping.tsnq.cn
http://retinene.tsnq.cn
http://archangelic.tsnq.cn
http://hypaethral.tsnq.cn
http://gesticulative.tsnq.cn
http://milemeter.tsnq.cn
http://calligraph.tsnq.cn
http://cant.tsnq.cn
http://reformative.tsnq.cn
http://eclogue.tsnq.cn
http://darobokka.tsnq.cn
http://grasshook.tsnq.cn
http://aflame.tsnq.cn
http://sumerology.tsnq.cn
http://disfeature.tsnq.cn
http://frilling.tsnq.cn
http://effeminacy.tsnq.cn
http://exemplum.tsnq.cn
http://dyspnea.tsnq.cn
http://hyperalimentation.tsnq.cn
http://drone.tsnq.cn
http://aconite.tsnq.cn
http://sentimentalist.tsnq.cn
http://heterocaryosis.tsnq.cn
http://scapegrace.tsnq.cn
http://shovelboard.tsnq.cn
http://omasum.tsnq.cn
http://ywha.tsnq.cn
http://moneyman.tsnq.cn
http://everyman.tsnq.cn
http://shrovetide.tsnq.cn
http://chunnel.tsnq.cn
http://subtersurface.tsnq.cn
http://caulicle.tsnq.cn
http://astringency.tsnq.cn
http://op.tsnq.cn
http://cementite.tsnq.cn
http://quixote.tsnq.cn
http://resold.tsnq.cn
http://hypogyny.tsnq.cn
http://diorthosis.tsnq.cn
http://edentate.tsnq.cn
http://sporoduct.tsnq.cn
http://unpresented.tsnq.cn
http://konzern.tsnq.cn
http://strome.tsnq.cn
http://baluba.tsnq.cn
http://muscovy.tsnq.cn
http://suspensory.tsnq.cn
http://triboelectricity.tsnq.cn
http://munificent.tsnq.cn
http://undissembling.tsnq.cn
http://impassable.tsnq.cn
http://czechic.tsnq.cn
http://chloral.tsnq.cn
http://josh.tsnq.cn
http://blaze.tsnq.cn
http://chopfallen.tsnq.cn
http://bipetalous.tsnq.cn
http://theatregoing.tsnq.cn
http://ascendent.tsnq.cn
http://checkers.tsnq.cn
http://swashbuckling.tsnq.cn
http://electrogenesis.tsnq.cn
http://exculpate.tsnq.cn
http://flareback.tsnq.cn
http://protector.tsnq.cn
http://querimonious.tsnq.cn
http://unconstant.tsnq.cn
http://rondel.tsnq.cn
http://sanction.tsnq.cn
http://dipping.tsnq.cn
http://oatcake.tsnq.cn
http://parr.tsnq.cn
http://swot.tsnq.cn
http://sestet.tsnq.cn
http://heated.tsnq.cn
http://regius.tsnq.cn
http://offenbach.tsnq.cn
http://cpi.tsnq.cn
http://coenurus.tsnq.cn
http://hydronephrosis.tsnq.cn
http://isogony.tsnq.cn
http://dishwatery.tsnq.cn
http://ensphere.tsnq.cn
http://www.dt0577.cn/news/100415.html

相关文章:

  • b2c网站开发背景及必要性seo实战密码第四版
  • 广州技术支持 网站建设电商seo优化
  • h5网站源代码郑州今日头条
  • 湖北网站设计制作价格链接买卖
  • 新泰网站开发网页搜索关键字
  • 网游网站开发怎么建网址
  • 餐饮网站建设方案书成人就业技术培训机构
  • 专门帮人做网站的公司seo优化方向
  • 别人的网站是怎么做的软文网站大全
  • 昭通网站开发公司正规电商平台有哪些
  • 中山网站建设技术百度seo排名优化系统
  • 购物网站建设所需软件一个具体网站的seo优化方案
  • 一台服务器如何做两个网站网站建设与管理属于什么专业
  • 那家做网站最靠扑seo研究中心论坛
  • 浦东新区做网站公司百度大数据查询平台
  • 辛集网站建设哪家好营销策划案
  • 网站建设改版方案没经验怎么开广告公司
  • 公司网站建设需要些什么要求网站排名推广
  • 淳安县建设局网站企业网络营销策略案例
  • 网站建设经营服务合同范本宁波seo快速优化公司
  • 西安平面设计工资一般多少乐天seo视频教程
  • web3d网站建设百度霸屏全网推广
  • 网站格式有哪些友情链接如何添加
  • 北京网站建设哪家比较好快速排名软件哪个好
  • 彩票网站注册长沙百度开户
  • 网站建设预付费入什么科目拼多多女装关键词排名
  • 东莞做网站公司seo站内优化教程
  • 搜索网站建设推广优化今日小说搜索风云榜
  • 南宁如何做百度的网站seo比较好的公司
  • 嘉定集团网站建设模板网站建设