当前位置:网站首页>【7.21-26】代码源 - 【好序列】【社交圈】【namonamo】
【7.21-26】代码源 - 【好序列】【社交圈】【namonamo】
2022-07-29 00:53:00 【ZhgDgE】
#613. 好序列
题意:有一个长为 n n n 的序列 A 1 , A 2 , ⋯ , A n A_1,A_2,\cdots,A_n A1,A2,⋯,An 。定义一个序列 { A } \{A\} { A} 是好的, 当且仅当他的每一个子区间 [ l , r ] [l,r] [l,r] 满足,至少存在一个元素 x x x 仅出现了一次。 ( n ≤ 2 × 1 0 5 ) (n\leq 2\times 10^5) (n≤2×105)
思路:启发式分治。详见【启发式分治】启发式合并的逆思想
AC代码:http://oj.daimayuan.top/submission/299119
#606. 社交圈
题意:现在有 N N N 个人,每一个人都不想周围的人坐得离他很近,所以在他的左边要放 L i L_i Li 张空椅子,右边要放 R i R_i Ri 张空椅子,同时每个人自己要坐 1 1 1 张椅子。现在他们要坐成若干个圈,请问最少要放多少张椅子(包括每个人自己坐的椅子)?
思路:把 { L } , { R } \{L\},\{R\} { L},{ R} 排序匹配即可,这样贪心一定最小。那么这种匹配方法是否有解呢,一定有解。因为这样重组匹配类似于置换,而置换可以拆分成图论里的若干个环,和题意 若干个圈 是一样的。
AC代码:http://oj.daimayuan.top/submission/298809
#678. namonamo
题意:给定字符串,问是否能拆分为两个相等的子序列。 ∣ S ∣ ≤ 40 |S|\leq 40 ∣S∣≤40
题解:(折半搜索) 代码源每日一题Div1 namonamo
思路:我们可以爆搜,但是 O ( 2 40 ) O(2^{40}) O(240) 不可行。我们可以使用折半搜索,对序列的前半部分和后半部分分别爆搜,然后枚举左边的搜索结果,在右边查询,时间复杂度 O ( 2 20 × log 2 20 ) O(2^{20}\times \log 2^{20}) O(220×log220) 。
边栏推荐
- Lombook User Guide
- Six noteworthy cloud security trends in 2022
- 梅克尔工作室——HarmonyOS实现列表待办
- Comprehensive upgrade, all you can imagine is here -- JD API interface
- Plato launched the LAAS protocol elephant swap, which allows users to earn premium income
- Understand various paths
- 全新升级:获得淘宝商品详情“高级版” API
- With the explosive growth of digital identity in 2022, global organizations are facing greater network security
- How to deal with the DDoS attack on the game server and how to defend it?
- Reinforcement learning (III): dqn, nature dqn, double dqn, with source code interpretation
猜你喜欢

Analysys analysis: focus on users, improve the user experience of mobile banking, and help the growth of user value

SiC功率半导体产业高峰论坛成功举办

J9数字论:什么因素决定NFT的价值?

How many of the top ten test tools in 2022 do you master

Redis is installed on Linux
![[hcip] two mGRE networks are interconnected through OSPF (ENSP)](/img/fe/8bb51ac48f52d61e8d31af490300bb.png)
[hcip] two mGRE networks are interconnected through OSPF (ENSP)
![[search] - iteration deepening / bidirectional dfs/ida*](/img/88/d460276a657cfc49eff10015c29e5d.png)
[search] - iteration deepening / bidirectional dfs/ida*

【HCIP】MPLS 基础

Network security litigation risk: four issues that chief information security officers are most concerned about

How to protect WordPress website from network attack? It is essential to take safety measures
随机推荐
科研环境对人的影响是很大的
JS事件简介
Redis is installed on Linux
【GoLang】网络连接 net.Dial
新1688 API 接入说明
J9数字论:什么因素决定NFT的价值?
[机缘参悟-54]:《素书》-1-事物缘起[原始章第一]:大道至简。
els 到底停止
Timer of BOM series
如何选择专业、安全、高性能的远程控制软件
How to choose professional, safe and high-performance remote control software
Moonbeam上的多链用例解析——Derek在Polkadot Decoded 2022的演讲文字回顾
2022年最火的十大测试工具,你掌握了几个
SQL question brushing: find the current salary details and department number Dept_ no
Super technology network security risk assessment service, comprehensively understand the security risks faced by the network system
[search] - DFS pruning and optimization
[search] - iteration deepening / bidirectional dfs/ida*
ELS square movement
剑指offer专项突击版第13天
【Golang】- runtime.Goexit()