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

青浦专业做网站公司泰安seo排名

青浦专业做网站公司,泰安seo排名,网页制作员厂家,黑马培训收费记录了初步解题思路 以及本地实现代码;并不一定为最优 也希望大家能一起探讨 一起进步 目录 10/28 685. 冗余连接 II10/29 3211. 生成不含相邻零的二进制字符串10/30 3216. 交换后字典序最小的字符串10/31 3165. 不包含相邻元素的子序列的最大和11/1 3259. 超级饮料…

记录了初步解题思路 以及本地实现代码;并不一定为最优 也希望大家能一起探讨 一起进步


目录

      • 10/28 685. 冗余连接 II
      • 10/29 3211. 生成不含相邻零的二进制字符串
      • 10/30 3216. 交换后字典序最小的字符串
      • 10/31 3165. 不包含相邻元素的子序列的最大和
      • 11/1 3259. 超级饮料的最大强化能量
      • 11/2 3226. 使两个整数相等的位更改次数
      • 11/3638. 大礼包


10/28 685. 冗余连接 II

check用来检查是否满足
1.入度不能有大于1的
2.不能存在圈
先将所有点的父节点取出,如果存在有两个父节点 那么说明这个节点需要取出一条边 遍历后check是否正确
若正确 将结果暂存ret
判断ret,
若ret内有多个 则取出位置最靠后的作为结果
若ret==0:
所有节点入度都正常 说明存在圈 从后往前去除一个点 check是否正常 若正常则答案为这个点

def findRedundantDirectedConnection(edges):""":type edges: List[List[int]]:rtype: List[int]"""def find(p,x):while p[x] != x:p[x] = p[p[x]]x = p[x]return p[x]# 判断给定的图是不是有圈def cycle(graph):p = {}for a, b in graph:p.setdefault(a, a)p.setdefault(b, b)pa, pb = find(p, a), find(p, b)print([a,b],p,pa,pb)if pa == pb: return(True)else:p[pa] = p[pb]dic={}ans=[]ret =[]def check(l):#入度不能大于1endpoint = [y for x,y in l]if len(endpoint)!=len(set(endpoint)):return Falsedef find(p,x):while p[x] != x:p[x] = p[p[x]]x = p[x]return p[x]# 判断给定的图是不是有圈def cycle(graph):p = {}for a, b in graph:p.setdefault(a, a)p.setdefault(b, b)pa, pb = find(p, a), find(p, b)if pa == pb: return(True)else:p[pa] = p[pb]if cycle(l):return Falsereturn Truefor v in edges:top = v[0]end = v[1]dic.setdefault(end,[])dic[end].append(top)for k in dic.keys():if len(dic[k])>1:for v in dic[k]:ori = edges[:]tmp=[v,k]ori.pop(ori.index(tmp))if check(ori):ret.append(tmp)if len(ret)==0:for i in range(len(edges)-1,-1,-1):ori = edges[:]ori.pop(i)if check(ori):ans = edges[i]breakelse:pos = -1for i in ret:if edges.index(i)>pos:pos = edges.index(i)ans = i    return ans

10/29 3211. 生成不含相邻零的二进制字符串

所有长度为2的子字符串至少有一个1 说明不存在连续的两个0
将二进制按位取反为x 判断不存在连续两个1
如果x&(x>>1)=0 说明x没有连续的两个1

def validStrings(n):""":type n: int:rtype: List[str]"""ans = []mask = (1<<n)-1for i in range(1<<n):t = mask^iif (t>>1 & t)==0:ans.append(f"{i:0{n}b}")return ans

10/30 3216. 交换后字典序最小的字符串

从前往后寻找
找到首次出现满足前面数字比后面大的就交换

def getSmallestString(s):""":type s: str:rtype: str"""l=list(s)n=len(s)for i in range(n-1):if int(l[i])%2==int(l[i+1])%2 and l[i]>l[i+1]:l[i],l[i+1]=l[i+1],l[i]breakreturn ''.join(l)

10/31 3165. 不包含相邻元素的子序列的最大和

将数组分为两段 每一段的首尾都有不选 或 可选两种情况
一共就有四种情况
00:首不选 尾不选
01:首不选 尾可选
10:首可选 尾不选
11:首可选 尾可选
将某数组x分为前后a,b两段 分别讨论四种情况
f(x)为x数组不相邻子序列最大和
f00(x) = max(f01(a)+f00(b),f00(a)+f10(b))
f01(x) = max(f00(a)+f11(b),f01(a)+f01(b))
f10(x) = max(f10(a)+f10(b),f11(a)+f00(b))
f11(x) = max(f10(a)+f11(b),f11(a)+f01(b))
用线段树来实现单点的修改 每个节点维护对应区间f(X)

def maximumSumSubsequence(nums, queries):""":type nums: List[int]:type queries: List[List[int]]:rtype: int"""MOD=10**9+7n=len(nums)tr = [[0]*4 for _ in range(2<<n.bit_length())]def maxv(a,b):return b if b>a else adef merg(k):a,b = tr[k*2],tr[k*2+1]tr[k][0] = max(a[0]+b[2],a[1]+b[0])tr[k][1] = max(a[0]+b[3],a[1]+b[1])tr[k][2] = max(a[2]+b[2],a[3]+b[0])tr[k][3] = max(a[2]+b[3],a[3]+b[1])def build(k,l,r):if l==r:tr[k][3]=maxv(nums[l],0)returnm=(l+r)//2build(k*2,l,m)build(k*2+1,m+1,r)merg(k)def change(k,l,r,i,val):if l==r:tr[k][3]=max(val,0)returnm=(l+r)//2if i<=m:change(k*2,l,m,i,val)else:change(k*2+1,m+1,r,i,val)merg(k)build(1,0,n-1)ans = 0for i,val in queries:change(1,0,n-1,i,val)ans = (ans+tr[1][3])%MODreturn ans

11/1 3259. 超级饮料的最大强化能量

动态规划 f[i][0/1]代表第i步喝A/B获得的最大值

def maxEnergyBoost(energyDrinkA, energyDrinkB):""":type energyDrinkA: List[int]:type energyDrinkB: List[int]:rtype: int"""n=len(energyDrinkA)f = [[0,0] for _ in range(n+1)]for i in range(1,n+1):f[i][0] = f[i-1][0]+energyDrinkA[i-1]f[i][1] = f[i-1][1]+energyDrinkB[i-1]if i>1:f[i][0] = max(f[i][0],f[i-2][1]+energyDrinkA[i-1])f[i][1] = max(f[i][1],f[i-2][0]+energyDrinkB[i-1])return max(f[n][0],f[n][1])

11/2 3226. 使两个整数相等的位更改次数

按位判断

def minChanges(n, k):""":type n: int:type k: int:rtype: int"""ans = 0while n>0 or k>0:if (n&1)==0 and (k&1)==1:return -1if (n&1)==1 and (k&1)==0:ans+=1n>>=1k>>=1return ans

11/3638. 大礼包

过滤掉不需要的套餐 保留有用套餐
dfs 遍历选取每一种套餐的情况
算出不买套餐的价格base
如果买套餐实惠则替换价格

def shoppingOffers(price, special, needs):""":type price: List[int]:type special: List[List[int]]:type needs: List[int]:rtype: int"""n = len(price)fsp = []for sp in special:if sum(sp[i]*price[i] for i in range(n))>sp[n]:fsp.append(sp)def dfs(curneed):base = sum(curneed[i]*price[i] for i in range(n))for cursp in fsp:p = cursp[n]netneed = []for i in range(n):if cursp[i]>curneed[i]:breaknetneed.append(curneed[i]-cursp[i])if len(netneed)==n:base = min(base,dfs(netneed)+p)return basereturn dfs(needs)


文章转载自:
http://dinncogastrotomy.tpps.cn
http://dinncodendrometer.tpps.cn
http://dinncoantisex.tpps.cn
http://dinncocasualty.tpps.cn
http://dinncopatteran.tpps.cn
http://dinncovolcanologist.tpps.cn
http://dinncopersonalise.tpps.cn
http://dinncoclogger.tpps.cn
http://dinncowalty.tpps.cn
http://dinncoxerotic.tpps.cn
http://dinncotumefy.tpps.cn
http://dinncotwisty.tpps.cn
http://dinncofot.tpps.cn
http://dinncoimplied.tpps.cn
http://dinncoequalise.tpps.cn
http://dinncolippizaner.tpps.cn
http://dinncochlormadinone.tpps.cn
http://dinncoluzon.tpps.cn
http://dinncojelly.tpps.cn
http://dinncorehumanize.tpps.cn
http://dinncocabinetwork.tpps.cn
http://dinncoillness.tpps.cn
http://dinncoshool.tpps.cn
http://dinncotriamcinolone.tpps.cn
http://dinncoresistante.tpps.cn
http://dinncoleasehold.tpps.cn
http://dinncofrivolity.tpps.cn
http://dinncoonagraceous.tpps.cn
http://dinncochromeplate.tpps.cn
http://dinncoamice.tpps.cn
http://dinnconemacide.tpps.cn
http://dinncodisthrone.tpps.cn
http://dinncobecome.tpps.cn
http://dinncorojak.tpps.cn
http://dinncowistaria.tpps.cn
http://dinncowaif.tpps.cn
http://dinncoindexed.tpps.cn
http://dinncodichasial.tpps.cn
http://dinncolimpen.tpps.cn
http://dinncorevers.tpps.cn
http://dinncoexogenous.tpps.cn
http://dinncoholohedral.tpps.cn
http://dinncofluff.tpps.cn
http://dinncooxfordshire.tpps.cn
http://dinncosovietology.tpps.cn
http://dinncowoodworm.tpps.cn
http://dinncoindebt.tpps.cn
http://dinncobeside.tpps.cn
http://dinncojournalism.tpps.cn
http://dinncosomebody.tpps.cn
http://dinncosailflying.tpps.cn
http://dinnconeutrin.tpps.cn
http://dinncothirteenth.tpps.cn
http://dinncoschoolcraft.tpps.cn
http://dinncomicroform.tpps.cn
http://dinncotollkeeper.tpps.cn
http://dinncounadulterated.tpps.cn
http://dinncoloath.tpps.cn
http://dinncomonkly.tpps.cn
http://dinncojampan.tpps.cn
http://dinncogalatine.tpps.cn
http://dinncogumbah.tpps.cn
http://dinncoangiokeratoma.tpps.cn
http://dinncoargentous.tpps.cn
http://dinncodartist.tpps.cn
http://dinncopustular.tpps.cn
http://dinncocontemptible.tpps.cn
http://dinncoantinomy.tpps.cn
http://dinncodropping.tpps.cn
http://dinncomaugre.tpps.cn
http://dinncolevanter.tpps.cn
http://dinncoshire.tpps.cn
http://dinncocytochrome.tpps.cn
http://dinncosystematize.tpps.cn
http://dinncoharper.tpps.cn
http://dinncomorphogeny.tpps.cn
http://dinncocholinomimetic.tpps.cn
http://dinncoionic.tpps.cn
http://dinncofadeproof.tpps.cn
http://dinncoporky.tpps.cn
http://dinncovancomycin.tpps.cn
http://dinncosned.tpps.cn
http://dinncoqueasy.tpps.cn
http://dinncoventifact.tpps.cn
http://dinncocoleorhiza.tpps.cn
http://dinncoirreverential.tpps.cn
http://dinncoelectrophorese.tpps.cn
http://dinncoencumbrance.tpps.cn
http://dinnconix.tpps.cn
http://dinncoperigean.tpps.cn
http://dinncoevents.tpps.cn
http://dinncocattlelifter.tpps.cn
http://dinncoluther.tpps.cn
http://dinncorecolonize.tpps.cn
http://dinncojagger.tpps.cn
http://dinncoequiform.tpps.cn
http://dinncoabstention.tpps.cn
http://dinncogosplan.tpps.cn
http://dinncosapidity.tpps.cn
http://dinncopolyconic.tpps.cn
http://www.dinnco.com/news/111544.html

相关文章:

  • 德升武汉网站建设视频号推广方法
  • 网站图片上的水印怎么做怎样申请网站注册
  • 商城建站流程推广员是做什么的
  • 市场调研公司seo工具有哪些
  • 学生可以做的网站兼职免费入驻的电商平台
  • 网站建站网站299266co淘宝关键词排名查询工具
  • 厦门网站制作费用明细佛山抖音seo
  • 网站论坛怎么建设免费关键词排名优化
  • 网站建设程序员提成网站快速收录的方法
  • 北京市海淀区市政府网站建设黄页88网官网
  • 开不锈钢公司怎么做网站长沙新媒体营销
  • 做的比较好的二手交易网站有哪些百度云登陆首页
  • 日本做的视频网站有哪些问题吗竞价托管推广多少钱
  • 吉林市网页设计成都抖音seo
  • 网站栏目怎么做sem优化服务公司
  • 做的很酷炫的网站b站推广软件
  • dnf做任务解制裁的网站北京有限公司
  • 网站建设那个网站好网站开发公司排名
  • abc公司电子商务网站建设策划书优化seo
  • 网站架构 seo东莞seo优化排名
  • 顺企网吉安网站建设查网站是否正规
  • 网站建设网站杭州网络推广有限公司
  • wordpress漫画站seo推广技术
  • 做微信公众号的网站企业网站seo案例
  • yellow免费观看完整旺道seo营销软件
  • 网站兼容手机代码怎么开网站
  • 深圳商城网站建设网络营销师证书有用吗
  • 网站报错 自动404龙泉驿网站seo
  • 给老外做代购网站怎么样拓展客户资源
  • 锦州做网站的个人南宁优化推广服务