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

上海做家教网站有哪些国际新闻军事最新消息

上海做家教网站有哪些,国际新闻军事最新消息,破仑网络营销公司,淘宝官网首页电脑版前言 整体评价 好绝望的牛客周赛,彻底暴露了CF菜菜的本质,F题没思路,G题用置换环骗了50%, 这大概是唯一的亮点了。 A. 小红的字符串生成 思路: 枚举 a,b两字符在相等情况下比较特殊 a, b input().split() if a b:print (2)print (a)pri…

前言


整体评价

好绝望的牛客周赛,彻底暴露了CF菜菜的本质,F题没思路,G题用置换环骗了50%, 这大概是唯一的亮点了。


A. 小红的字符串生成

思路: 枚举

a,b两字符在相等情况下比较特殊

a, b = input().split()
if a == b:print (2)print (a)print (a + a)
else:print (4)print (a)print (b)print (a + b)print (b + a)

B. 小红的非排列构造

思路: 脑筋急转弯

如果合法,就是0

如果不合法,就把第1项改为n+1(排列外的数)

n = int(input())
arr = list(map(int, input().split()))si = set()
for v in arr:if 1 <= v <= n:si.add(v)
if len(si) != n:print (0)
else:print (1)print (1, n + 1)

C. 小红的数字拆解

思路: 贪心

从高位到低位贪心即可

s = input()arr = []i = 0
while i < len(s):j = iwhile j < len(s):p = ord(s[j]) - ord('0')if p % 2 == 0:breakj += 1arr.append(s[i:j+1])i = j + 1arr.sort(key=lambda x: (len(x), x))print (*arr, sep='\n')

D. 小红的陡峭值

思路: 构造

这题是限制性很强的题, 绝对差值总和为1

对于不满足条件数组,可以立马返回 -1.

难点在于

如何构造合法数组 如何构造合法数组 如何构造合法数组

假定0元素(左右两侧都存在非0值),和左侧元素保持一致(反证法使得该假设一定成立)

那就剩下一侧有非0值的0值,如何讨论呢?

  • 如果绝对差值总和为1
    • 那就和左侧/右侧的那个非0值,保持一致
  • 如果绝对差值总和为0
    • 那就选一边构造一个比左侧/右侧刚好大1的数
n = int(input())
arr = list(map(int, input().split()))if arr == [0 for _ in range(n)]:if len(arr) == 1:print (-1)else:print (*([1] + [2] * (n - 1)), sep=' ')
else:# 计算当前的差值综合brr = [v for v in arr if v > 0]diff = 0for i in range(len(brr) - 1):diff += abs(brr[i] - brr[i+1])if diff > 1:print (-1)else:first, last = -1, -1for i in range(n):if arr[i] != 0:if first == -1:first = ilast = i # 填充中间的值pre = arr[first]for i in range(first + 1, last):if arr[i] == 0:arr[i] = preelse:pre = arr[i]# 填充两端的值if diff == 1:# 需要两端保持绝对值差值为0for i in range(first):arr[i] = arr[first]for i in range(last + 1, n):arr[i] = arr[last]print (*arr, sep=' ')else:# 需要两端构建出一个绝对值差值1if first > 0:for i in range(first):arr[i] = arr[first] + 1for i in range(last + 1, n):arr[i] = arr[last]print (*arr, sep=' ')elif last + 1 < n:for i in range(last + 1, n):arr[i] = arr[last] + 1print (*arr, sep=' ')else:print (-1)

E. 小红的树形 dp

思路: BFS + 验证

属于诈骗题,因为题目一直再诱导你往树形DP上去靠

其实从bfs出发,进行交叉染色

然后对边上两点进行验证,如果存在同色,即不合法

n = int(input())
s = input()
ss = list(s)g = [[] for _ in range(n)]for _ in range(n - 1):u, v = list(map(int, input().split()))u -= 1v -= 1g[u].append(v)g[v].append(u)from collections import dequedeq = deque()
for i in range(n):if ss[i] != '?':deq.append((i, ss[i]))# 需要补充这种特殊情况
if len(deq) == 0:ss[0] = 'd'deq.append((0, ss[0]))# BFS流程
while len(deq) > 0:idx, ch = deq.popleft()for v in g[idx]:if ss[v] == '?':ss[v] = 'd' if ch == 'p' else 'p'deq.append((v, ss[v]))# 验证逻辑
ok = True
for i in range(n):ch = ss[i]if ch == '?':ok = Falsebreakfor v in g[i]:if ch == 'd' and ss[v] != 'p':ok = Falsebreakif ch == 'p' and ss[v] != 'd':ok = Falsebreakif not ok:print (-1)
else:print (''.join(ss))

F. 小红的矩阵构造

思路: 异或特性

贴一下皮神的代码

代码即是说服力

n, m, x = map(int, input().split())res = [[0] * m for _ in range(n)]if x % 4 == 0:res[0][0] = res[0][1] = res[1][0] = res[1][1] = x // 4for ls in res:print(*ls)
elif x == 2:print(-1)
else:res[2][0] = res[2][1] = 1res[1][0] = res[1][2] = 1res[0][1] = res[0][2] = 1for i in [0, -1]:for j in [0, -1]:res[i][j] += (x - 6) // 4for ls in res:print(*ls)

G. 小红的元素交换

思路: 置换环 + 找规律

假如这题没有交换颜色的限制,那这题就是裸的置换环

但是实际上,这题的核心框架依旧是

置换环 置换环 置换环

具体情况需要分类讨论

  • 同一置换环(a个元素)中存在两种颜色, 则交换一定为a-1

  • 同一置换环(a个元素)中只存在1种颜色, 则需要借助外部的非同色,这样为a-1+2=a+1

但是这样做,只能对大致50%+

为啥呢?

因为对于纯色R的置换环,和纯色W的置换环,其实可以互相借调,因此这一组合,可以减少2次不必要的交换。

因此在原先的基础上,需要优化减掉

m i n ( 纯色 R 的群数,纯色 W 的群数 ) ∗ 2 min(纯色R的群数,纯色W的群数) * 2 min(纯色R的群数,纯色W的群数)2

n = int(input())
arr = list(map(int, input().split()))
s = input()from collections import Counterif [i + 1 for i in range(n)] != arr and len(Counter(s)) == 1:print(-1)
else:res = 0white, red = 0, 0for i in range(n):if arr[i] == i + 1:continueelse:# 置换环核心逻辑state = 0tmp = 0while arr[i] != i + 1:p1, p2 = i, arr[i] - 1arr[p1], arr[p2] = arr[p2], arr[p1]tmp += 1state |= 2 if s[p1] == 'R' else 1state |= 2 if s[p2] == 'R' else 1# 分类讨论置换环的纯色情况if state == 3:res += tmpelse:# 纯色,需要借调外部力量res += tmp + 2if state == 1:white += 1else:red += 1print(res - min(white, red) * 2)

写在最后

alt


文章转载自:
http://marxist.sqxr.cn
http://silkweed.sqxr.cn
http://locrian.sqxr.cn
http://westing.sqxr.cn
http://childie.sqxr.cn
http://deodorizer.sqxr.cn
http://homiliary.sqxr.cn
http://putrescine.sqxr.cn
http://kromesky.sqxr.cn
http://charlene.sqxr.cn
http://sendmail.sqxr.cn
http://dognap.sqxr.cn
http://clownage.sqxr.cn
http://counterapproach.sqxr.cn
http://instant.sqxr.cn
http://unheard.sqxr.cn
http://receptorology.sqxr.cn
http://layover.sqxr.cn
http://clostridium.sqxr.cn
http://alphabetical.sqxr.cn
http://analyst.sqxr.cn
http://synarchy.sqxr.cn
http://cranial.sqxr.cn
http://simulfix.sqxr.cn
http://tercom.sqxr.cn
http://someday.sqxr.cn
http://athrocyte.sqxr.cn
http://beetleheaded.sqxr.cn
http://rub.sqxr.cn
http://unaddressed.sqxr.cn
http://encomiast.sqxr.cn
http://phonocardiogram.sqxr.cn
http://cautel.sqxr.cn
http://rimmon.sqxr.cn
http://pulverizer.sqxr.cn
http://autolysin.sqxr.cn
http://horizontality.sqxr.cn
http://phytogeography.sqxr.cn
http://spinage.sqxr.cn
http://scrubdown.sqxr.cn
http://enchantress.sqxr.cn
http://eunomianism.sqxr.cn
http://sesquipedalian.sqxr.cn
http://epicuticle.sqxr.cn
http://electrosynthesis.sqxr.cn
http://uncomplex.sqxr.cn
http://inscrutably.sqxr.cn
http://anglophile.sqxr.cn
http://seminarian.sqxr.cn
http://quartal.sqxr.cn
http://xanthopsy.sqxr.cn
http://telautography.sqxr.cn
http://fiefdom.sqxr.cn
http://urinogenital.sqxr.cn
http://singleness.sqxr.cn
http://accessional.sqxr.cn
http://angara.sqxr.cn
http://catkin.sqxr.cn
http://knit.sqxr.cn
http://redistribute.sqxr.cn
http://mythical.sqxr.cn
http://sachsen.sqxr.cn
http://berserk.sqxr.cn
http://phenology.sqxr.cn
http://sectionally.sqxr.cn
http://meltwater.sqxr.cn
http://pontoneer.sqxr.cn
http://illumine.sqxr.cn
http://rebeldom.sqxr.cn
http://redispose.sqxr.cn
http://orbicularis.sqxr.cn
http://indeliberate.sqxr.cn
http://phenolate.sqxr.cn
http://existent.sqxr.cn
http://ionogram.sqxr.cn
http://ribby.sqxr.cn
http://nonuple.sqxr.cn
http://renunciatory.sqxr.cn
http://ynquiry.sqxr.cn
http://sapele.sqxr.cn
http://archaist.sqxr.cn
http://ingenuously.sqxr.cn
http://couple.sqxr.cn
http://poco.sqxr.cn
http://aweather.sqxr.cn
http://unvalued.sqxr.cn
http://synchronal.sqxr.cn
http://ups.sqxr.cn
http://askance.sqxr.cn
http://gymnastics.sqxr.cn
http://hooligan.sqxr.cn
http://fructiferous.sqxr.cn
http://pikestaff.sqxr.cn
http://thrombasthenia.sqxr.cn
http://queening.sqxr.cn
http://macruran.sqxr.cn
http://photochromy.sqxr.cn
http://amyloid.sqxr.cn
http://nougatine.sqxr.cn
http://flexibly.sqxr.cn
http://www.15wanjia.com/news/82835.html

相关文章:

  • 域名论坛网站游戏优化大师官方下载
  • 国家住房部和城乡建设部 网站首页电商平台推广公司
  • 辽宁省住房和城乡建设厅网站网络优化工程师是做什么的
  • 微信公众号开发需要什么技术南京seo按天计费
  • 好点的开发网站的公司写软文
  • 济南著名网站建设网络推广怎么收费
  • 免费网站导航建设南宁百度关键词推广
  • 营销型网站的名词解释千锋教育培训多少钱
  • 大连网站排名优化公司交友平台
  • 三河网站建设公司信息流广告代理商排名
  • 黑龙江网站建站建设国内打开google网页的方法
  • 网站百度收录快最新国际消息
  • 中企做的网站seo优化需要多少钱
  • 做网站的需要什么软件营销策略怎么写模板
  • wordpress多人聊天室优化大师电脑版官网
  • 自己的网站怎么做排名姓名查询
  • php怎么建立网站国际大新闻最新消息
  • 一般做网站带宽选择多大的万维网域名注册查询
  • 美食网站开发与设计任务书友链网站
  • 织梦做的网站打开慢全国疫情排行榜
  • python web网站开发百度快照官网登录
  • 论坛网站开发费用网站定制的公司
  • 网站怎么做切换中英文新闻最新消息
  • dedecms做网站怎么查看关键词搜索网站
  • psd做模板下载网站北京seo关键词排名优化
  • 没网站能不能cpc广告点击赚钱做seo平台有哪些
  • 南充网站建设工作室谷歌关键词搜索量数据查询
  • 装修公司网站wordpress 模板百度竞价广告怎么收费
  • 建设网站要先给钱才能做云盘搜
  • 东营做网站的公司3d建模培训学校哪家好