二分
文章平均质量分 83
程序设计竞赛中二分相关知识
小飞猪Jay
远风知我意,微凉又深情。
展开
-
2106. 摘水果
前缀和,二分原创 2023-05-04 21:34:49 · 624 阅读 · 0 评论 -
codeforce. B. Code For 1
题意:给出三个整数n , l , r , n是给出的数字,l和r是范围。集合里面初始只有n一个元素,你每次可以使集合里任意一个大于一的数进行除二的操作,除二的余数放在当前位置,两侧分别是刚才的数除二的商。反复进行此操作,知道集合中只剩下1和0.问在l到r的范围里,有多少个1.思路:从这道题的题意我们就可以看到,每个数进行操作之后,左右两侧的数是一模一样的,那左右的操作也是一样的。那我们就可以...原创 2020-03-08 18:54:10 · 152 阅读 · 0 评论 -
codeforce. C. Perfect Team
题意: 有a,b,c三种数,有多少种三个数的组合,使得每组数,至少一个a一个b。思路: 二分是很显然的,但是还可以推公式。比赛的时候写的是二分。赛后看大牛的代码,貌似就3种情况:x,y,(x+y+z)/3。取最小值就可以了。理由的话,就是按种类数足的话,就按人数取,种类数不足的话,就按照种类数取。但是这样感觉还是不自然(没有严谨的数学推理)。假设三类数数目分别为x,y,z。令a = min(...转载 2020-02-25 11:06:57 · 227 阅读 · 0 评论 -
cf. (E) Thematic Contests
题意:第一行给出t,接着有t个问题,ai表示第i个问题的种类。现在想要举办比赛,每天一场比赛,每场比赛所有问题都是一个种类,第二天的问题数是前一天问题数的两倍,问最多的问题数思路:首先我们用mp来记录每个种类数,用a数组来记录种类数的问题数量。接着对a排序,然后就开始搜索过程。首先就是想到暴力,但是暴力会超时,于是改用stl自带的二分查找,就A了代码:#include<iostre...原创 2020-02-23 13:53:17 · 174 阅读 · 0 评论 -
C++中的Binary_search
之前遇到二分的问题,都会手动实现,如果稍有不慎就会在返回值或者是区间的开闭问题上犯错,在这里记录一下c++STL库中的函数,在一般情况下可以使用来提高效率。但二分的本质还是要掌握的。常用操作:头文件:#include使用方法:1.binary_search:查找某个元素是否出现a。函数模板:binary_search(arr[],arr[]+size,indx)b.参数说明:ar...原创 2020-01-15 15:24:22 · 8705 阅读 · 3 评论 -
银行贷款
题目描述当一个人从银行贷款后,在一段时间内他(她)将不得不每月偿还固定的分期付款。这个问题要求计算出贷款者向银行支付的利率。假设利率按月累计。输入格式三个用空格隔开的正整数。第一个整数表示贷款的原值,第二个整数表示每月支付的分期付款金额,第三个整数表示分期付款还清贷款所需的总月数。输出格式一个实数,表示该贷款的月利率(用百分数表示),四舍五入精确到0.1%。输入输出样例输入100...原创 2019-10-16 19:38:48 · 520 阅读 · 0 评论 -
二分图的最大匹配—匈牙利算法
二分图的最大匹配—匈牙利算法【基本概念】:二分图:二分图又称作二部图,是图论中的一种特殊模型。 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j分别属于这两个不同的顶点集(i in A,j in B),则称图G为一个二分图。无向图G为二分图的充分必要条件是,G至少有两个顶点,且其所有回路的长度均为偶数。最大匹配...转载 2019-09-16 21:13:23 · 190 阅读 · 0 评论 -
Longest Ordered Subsequence
A numeric sequence of ai is ordered if a1 < a2 < … < aN. Let the subsequence of the given numeric sequence ( a1, a2, …, aN) be any sequence ( ai1, ai2, …, aiK), where 1 <= i1 < i2 < ...原创 2019-04-24 18:20:08 · 183 阅读 · 0 评论 -
Expanding Rods POJ - 1905
E - Expanding Rods POJ - 1905When a thin rod of length L is heated n degrees, it expands to a new length L’=(1+n*C)*L, where C is the coefficient of heat expansion.When a thin rod is mounted on two ...原创 2019-04-19 17:50:14 · 159 阅读 · 0 评论 -
Frodo and pillows
n hobbits are planning to spend the night at Frodo’s house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants ...原创 2019-04-06 20:16:13 · 324 阅读 · 0 评论 -
Pie
My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of ...原创 2019-04-06 11:41:13 · 742 阅读 · 1 评论 -
Distributing Ballot Boxes
Today, besides SWERC’11, another important event is taking place in Spain which rivals it in importance: General Elections. Every single resident of the country aged 18 or over is asked to vote in ord...原创 2019-04-06 10:50:01 · 213 阅读 · 0 评论 -
The Meeting Place Cannot Be Changed
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.At some points on the road t...原创 2019-03-30 09:20:42 · 208 阅读 · 0 评论