
二分
S atur
要变成萤火虫~
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
L1-071 前世档案 (20 分) (类似二分)
传送门 题目描述: 思路:照我以前可能就会傻傻的去想怎么实现二叉树…也许是现在思维成熟了点,便能看出其实这就是类似于二分原理的水题。首先能够知道结论的总数,每次"y"和"n"的选择就像二分一样对半砍的操作,所以简单模拟下就行啦! AC代码: #include<bits/stdc++.h> #define int long long #define endl '\n' using namespace std; const int N = 1e5+10; int n, m,...原创 2022-03-23 09:11:29 · 1716 阅读 · 3 评论 -
Codeforces D. Cleaning the Phone (#697 Div.3) (二分 & 前缀和)
传送门 题意: 有 n 个软件,第 i 个软件占 a[i] 的内存, 但有 b[i] 的贡献;现让删除一些软件,使得释放的空间达到 m 及以上,但牺牲的贡献值又要最小,并输出牺牲的最小贡献值。 思路: 参考于大佬博客 根据贡献值分别为 1 和 2 将内存 a 分成 a1 和 a2两个组,肯定先删内存大的软件,再按照内存大小降序排序。 所以贡献值为 1 的 a1 内的软件优先被删除,再利用二分 + 前缀和的方法找到除了 a1 外 a2 内再删除多少个能使得删除内存经量大。 再得注意,也许只删除 a2 中最原创 2021-02-02 17:24:18 · 234 阅读 · 0 评论 -
Codeforces D. Multiset (树状数组 & 二分)(Round 87 Rated for Div.2)
传送门 题意: 现有一个多元集合,你有如下两种操作: 将数k加入多元集合中 找到多元集合升序第k位,并将其删除 最后打印出集合中的任意元素,若集合为空直接输出0。 思路: 利用树状数组统计数值下标的个数, 通过树状数组的前缀和性质再使用二分锁定第k个数的位置。 代码实现: #include<bits/stdc++.h> #define lowbit(x) (x &(-x)) using namespace std; const int N = 1e6 + 500; int n,原创 2020-07-06 18:57:32 · 210 阅读 · 0 评论 -
POJ 3579 Median (二分套用)
传送门 题意: 给N数字, X1, X2, … , XN,我们计算每对数字之间的差值:∣Xi - Xj∣ (1 ≤ i < j ≤ N). 我们能得到 C(N,2) 个差值,现在我们想得到这些差值之间的中位数。 如果一共有m个差值且m是偶数,那么我们规定中位数是第(m/2)小的差值。 ( Xi ≤ 1,000,000,000 3 ≤ N ≤ 1,00,000 ) **思路:**很神奇的一个题 总共有 n * (n - 1) / 2个差值,那么比中位数大的就有 n * (n - 1) / 4个数 那么就原创 2020-06-07 19:19:03 · 287 阅读 · 0 评论 -
整数二分:数的范围
题目链接:https://www.acwing.com/problem/content/791/ 输入样例: 6 3 1 2 2 3 3 4 3 4 5 输出样例: 3 4 5 5 -1 -1 二分模板: // 区间[l, r]被划分成[l, mid]和[mid + 1, r]时: int bsearch_1(int l, int r) { while (l < r) { ...原创 2020-01-14 17:44:05 · 274 阅读 · 0 评论 -
二分:HDU2899,2199
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2899 Problem Description Now, here is a fuction: F(x) = 6x ^ 7 + 8x ^ 6 + 7x ^ 3 + 5x ^ 2 - y *x (0 <= x <=100) Can you find the minimum value when...原创 2019-12-19 18:35:02 · 181 阅读 · 0 评论 -
Codeforces 348A. Mafia(贪心/二分)
A. Mafia 题目链接:https://codeforces.com/problemset/problem/348/A One day n friends gathered together to play “Mafia”. During each round of the game some player must be the supervisor and other n - 1 peop...原创 2019-12-19 16:34:14 · 222 阅读 · 0 评论 -
浮点数二分:数的三次方根
题目链接:https://www.acwing.com/problem/content/792/ 数据范围 −10000≤n≤10000 输入样例: 1000.00 输出样例: 10.000000 代码实现: #include<bits/stdc++.h> using namespace std; typedef long long ll; const int INF=0x3f3f3f...原创 2020-01-14 18:39:56 · 514 阅读 · 0 评论