
二分
文章平均质量分 81
CCloth
这个作者很懒,什么都没留下…
展开
-
[二分][二维前缀和]Valiant‘s New Map Codeforces1731D
很显然可以二分,关键在于判断是否存在满足题意的边长为k的子矩阵。判断的时候可以先扫一遍矩阵,将其中大于k的元素修改为k,然后求二位前缀和,扫描所有边长为k的子矩阵,若其二维区间和大小为k^3,那么就说明存在满足题意的子矩阵。给出一个n*m的矩阵,找出其中最大的一个k*k的子矩阵,满足其中所有的数组都大于等于k。原创 2022-12-30 12:33:07 · 704 阅读 · 0 评论 -
[二分][贪心]Tree Infection Codeforces1665C
可以想到应该先处理出来树上所有组兄弟节点,然后优先选择点数多的组进行感染,设组数为t,前t秒一定将所有t组先进行感染,否则显然不优,有了这个思路后就可以二分求出最短时间了,在check中可以求二分出的时间x内最多感染的节点个数,如果这个值大于等于n,那么return true。有一颗有根树,根节点为1,现在每秒可以按顺序做如下两个操作,第一个操作:对于每一组兄弟节点,如果其中某个节点被感染,那么可以将感染传播给其某一个兄弟节点。第二个操作:选择树上任意一个健康的点感染它。问将整棵树感染的最短时间。原创 2022-10-18 22:56:58 · 242 阅读 · 0 评论 -
[拓扑排序][二分]Toss a Coin to Your Graph... Codeforces1679D
二分答案,首先二分出一个x,check中检测是否能不经过大于x的点走完k-1步,而check的具体实现则需要重新建图,只考虑那些点权小于等于x的点,如果新图中出现了回路,那么显然一定可以return true,如果没有回路那新图就是一个DAG(有向无环图),直接拓扑排序求最远距离,如果最远距离大于等于k-1,那就可以return true,否则return false。给出n个点,m条有向边,以及一个参数k,每个点有一个点权,可以任选一个起点,并从该起点走k-1步,输出路径上最大值的最小值。原创 2022-09-22 22:57:47 · 265 阅读 · 0 评论 -
[贪心][预处理+二分][好题]Find the Number 2022ICPC第一场网络选拔赛D
赛时想的是另一种贪心的思路,首先枚举后缀零个数,假设后缀零有i个,然后考虑l和r的二进制表示,从第30位到第0位枚举。由于满足题意的数字并不是特别多,大概是5e5左右个,当时想到了打表,但显然是没法把这些数字全部放进代码里的,所以当时这条路就没走下去,但赛后发现完全可以把这些数字暴力求出来,然后放入15个vector中,暴搜的复杂度很低,大概也是5e5级别的,当求出符合题意的全部数字后这道题就很简单了,对于每个询问直接找出第一个大于等于l的数字,然后看它是否小于等于r,不得不说这种思路确实很强。原创 2022-09-18 16:30:32 · 1216 阅读 · 0 评论 -
[贪心][二分]Sort Zero Codeforces1712C
贪心地想,选择最靠前的非0数字最优,这是因为假如选择的是中间的非0数字,那么为了序列整体不减,前面的非0数字也一定要变成0,这样至少也要操作两次,但是直接选择最靠前的非0数字一定不会比这种方案差,毕竟它可以之后再选择中间的非0数字,甚至还会更优,因为这样是至少操作一次。所以贪心策略就是操作机会都用在最靠前的非0数字上,最后检查一下序列是否不减,最终复杂度为O(nlogn)。给出一个数组,你可以进行若干次操作,每次操作可以选择数组中某个数字x,令所有的x变成0,如果想得到一个不减序列的最少操作次数是多少。..原创 2022-08-14 23:58:15 · 347 阅读 · 0 评论 -
[二分][状压dp]Boss Rush 2022杭电多校第3场 1002
给出Boss的血量以及你可以使用的n个技能,每个技能最多用一次,并且每个技能使用完后有一段真空期ti不能释放其他技能,每个技能可以造成持续伤害,一共持续len秒,每秒造成di伤害,问最早击败Boss的时间,时间从0开始计算。每次更新完一个状态的伤害dp[i]后都可以和hp比较一下,如果大于等于hp那就说明x时间内可以击败Boss,如果没有状态能击败,那就说明x时间内不能击败Boss,最后输出二分结果即可。...原创 2022-07-27 22:35:39 · 239 阅读 · 0 评论 -
[好题][曼哈顿距离][二分]Taxi 2022杭电多校第3场 1011
在做这道题之前需要知道一个结论,找某点到各点曼哈顿距离最大值只需要看4个点,分别是x+y值最大的点、x-y值最大的点、-x+y值最大的点和-x-y值最大的点,这4点到给定点的曼哈顿距离最大值就是全部点到给定点的曼哈顿距离最大值。在一个二维平面上有n个点,每个点还具有一个点权wi,q次询问,每次询问给出一个点(x,y),该点到各点的代价为min(两点间曼哈顿距离,wi),求该点到各点代价的最大值。......原创 2022-07-27 09:14:35 · 583 阅读 · 0 评论 -
[二分]Mark and His Unfinished Essay CF1705C
由于这个字符串最终会非常长,所以不能直接保存下来,所以对于每次询问都需要向前找到它最初的位置,找之前可以先维护前i次操作后字符串的长度sum[i],这样找的过程其实就是个二分的过程,二分找到当前位置是从第几次copy得到的,之后计算出它向前的位置,重复这个过程直到当前位置落入1~n。有一个字符串s,以及c次copy操作,q次询问,每次copy操作给出一个区间[l,r],将s[l,r]这个子串拼接到原串后面构成新串s,c此操作后有q次询问,每次询问输出指定位置的字符。...原创 2022-07-16 10:52:12 · 419 阅读 · 0 评论 -
[贪心][二分]Occupy the Cities 2021CCPC桂林站G
这道题目有两种做法,分别是二分和贪心做法,比赛的时候没想到二分,就一直在想贪心的做法,后来没想到真的用贪心O(n)解决了。先考虑O(nlogn)的二分解法,由于攻占时间具有单调性,所以在最外层可以二分时间,对于确定的时间mid只需要判断是否能在mid时间内将全部城市攻占,有n座城市排成一横排,其中某些城市开始时被攻占,每座被攻占的城市可以在一个时间单位内攻占下其左侧或右侧未被攻占的城市,不过只能选择一侧,不可以同时攻占两侧城市,给出n座城市初始状态,求所有城市都被攻占的最少时间。...原创 2022-07-15 21:19:42 · 667 阅读 · 2 评论 -
[二分][贪心]Schedule Management CF1701C
There are nn workers and mm tasks. The workers are numbered from 11 to nn. Each task ii has a value aiai — the index of worker who is proficient in this task.Every task should have a worker assigned to it. If a worker is proficient in the task, they comple原创 2022-07-12 15:25:39 · 382 阅读 · 0 评论 -
[好题][二分][dp][贪心]River Locks CF1700D
Recently in Divanovo, a huge river locks system was built. There are now n locks, the i-th of them has the volume of vivi liters, so that it can contain any amount of water between 0 and vivi liters. Each lock has a pipe attached to it. When the pipe is op原创 2022-07-09 18:06:18 · 222 阅读 · 0 评论 -
[树状数组][二分]特殊堆栈 PTA L3-002
堆栈是一种经典的后进先出的线性结构,相关的操作主要有“入栈”(在堆栈顶插入一个元素)和“出栈”(将栈顶元素返回并从堆栈中删除)。本题要求你实现另一个附加的操作:“取中值”——即返回所有堆栈中元素键值的中值。给定 N 个元素,如果 N 是偶数,则中值定义为第 N/2 小元;若是奇数,则为第 (N+1)/2 小元。输入格式:输入的第一行是正整数 N(≤10^5)。随后 N 行,每行给出一句指令,为以下 3 种之一:Push keyPopPeekMedian其中key是不超过10^5...原创 2022-03-22 21:31:50 · 266 阅读 · 0 评论 -
[二分][细节]Copying Books POJ1505
Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scribers. The scriber had been given a book and after several months he finished its copy. One of the most famous s原创 2022-03-15 19:35:37 · 551 阅读 · 0 评论 -
[找规律][二分]杨辉三角 2021年蓝桥杯
题目描述下面的图形是著名的杨辉三角形:如果我们按从上到下、从左到右的顺序把所有数排成一列,可以得到如下数列:1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, ...给定一个正整数 N,请你输出数列中第一次出现 N 是在第几个数?输入输入一个整数 N。输出输出一个整数代表答案。样例输入6样例输出13提示【评测用例规模与约定】对于 20% 的评测用例,1 ≤ N ≤ 10;对于所有评测用例,1 ≤ N原创 2022-02-28 21:38:11 · 2198 阅读 · 1 评论 -
[好题][二分][前缀和]Best Cow Fences POJ2018
Farmer John's farm consists of a long row of N (1 <= N <= 100,000)fields. Each field contains a certain number of cows, 1 <= ncows <= 2000.FJ wants to build a fence around a contiguous group of these fields in order to maximize the average num原创 2022-01-21 23:55:48 · 251 阅读 · 0 评论 -
[二分][叉积]TOYS POJ2318
Calculate the number of toys that land in each bin of a partitioned toy box.Mom and dad have a problem - their child John never puts his toys away when he is finished playing with them. They gave John a rectangular box to put his toys in, but John is rebe原创 2021-10-25 15:57:24 · 311 阅读 · 0 评论 -
[好题][二分][字符串哈希]Checking the Text POJ2758
Wind's birthday is approaching. In order to buy a really really fantastic gift for her, Jiajia has to take a boring yet money-making job - a text checker.This job is very humdrum. Jiajia will be given a string of text what is English letters and he must c原创 2021-10-25 12:03:11 · 194 阅读 · 0 评论 -
[n串的最长公共子串][后缀数组]Corporate Identity POJ3450
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includes company logo but also other signs, like trademarks. One of such companies is Internet Building Masters (IBM), which has recently asked ACM for a help wit原创 2021-10-24 19:55:50 · 195 阅读 · 0 评论 -
[二分][后缀数组]Substrings POJ1226
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings.InputThe first line of the input contains a single integer原创 2021-10-23 20:09:46 · 122 阅读 · 0 评论 -
[二分][后缀数组]Finding Palindromes POJ3376
You are the King of Byteland. Your agents have just intercepted a batch of encrypted enemy messages concerning the date of the planned attack on your island. You immedietaly send for the Bytelandian Cryptographer, but he is currently busy eating popcorn an原创 2021-10-23 19:09:10 · 91 阅读 · 0 评论 -
[二分][后缀数组]Life Forms POJ3294
You may have wondered why most extraterrestrial life forms resemble humans, differing by superficial traits such as height, colour, wrinkles, ears, eyebrows and the like. A few bear no human resemblance; these typically have geometric or amorphous shapes l原创 2021-10-23 11:44:04 · 127 阅读 · 0 评论 -
[二分][后缀数组]Milk Patterns POJ3261
Farmer John has noticed that the quality of milk given by his cows varies from day to day. On further investigation, he discovered that although he can't predict the quality of milk from one day to the next, there are some regular patterns in the daily mil原创 2021-10-19 19:32:47 · 126 阅读 · 0 评论 -
[二分][后缀数组]Musical Theme POJ1743
A musical melody is represented as a sequence of N (1<=N<=20000)notes that are integers in the range 1..88, each representing a key on the piano. It is unfortunate but true that this representation of melodies ignores the notion of musical timing; bu原创 2021-10-19 18:55:10 · 113 阅读 · 0 评论