![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
二分
Dream-chasing ant
鄙人水平不高,建立博客初心只是想留一份回忆给自己。
展开
-
More Cowbell CodeForces - 604B
传送门 题意:n个数字,k个箱子,然后是很关键的一个点,一个箱子只能放1或者2个数字,问箱子的最大容量是多少。 做法:这道题是二分这我当时想到了,但我没有看到一个箱子最多只能放2个数这个条件。我们分的是最大容量。 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e5+10; int n,k; ll a[maxn]; bool check(ll x) { int cnt=0;原创 2020-07-09 17:32:44 · 98 阅读 · 0 评论 -
P2678 跳石头
传送门 找到最小的最大值,如果比这个值小就把石头移走,因为这个值是最小的跳跃距离。 #include<bits/stdc++.h> using namespace std; const int maxn=4e5+10; int a[maxn],n,m,k; bool check(int x){ int cnt=0,now=0; for(int i=1;i<=n+1;i++...原创 2020-03-22 12:07:23 · 220 阅读 · 0 评论 -
P1182 数列分段 Section II
传送门 这道题也是第二次做,第一次做看题解,这一次自己独立完成。我们二分最小的最大值,如果一个a[]大于这个最大值,显然是不合理的。如果cnt<=k就return true,为什么<也return true呢,因为这是在寻找最佳的答案 #include<bits/stdc++.h> using namespace std; typedef long long ll; c...原创 2020-03-22 09:55:28 · 91 阅读 · 0 评论 -
P3853 [TJOI2007]路标设置
传送门 这道题求的是最小的空旷距离,那我们二分空旷距离,有比它大的就将它分开,与题意比较次数 #include<bits/stdc++.h> using namespace std; const int maxn=2e5+10; int l,n,k; int a[maxn],f[maxn],sum; bool check(int x){ int cnt=0; for(int i...原创 2020-03-21 22:24:36 · 72 阅读 · 0 评论 -
P1024 一元三次方程求解
传送门 这道题看了题解,理解了一些,因为根x1与根x2之差绝对值大于等于1,只要符合f(x1)*f(x2)<0,那么就在这个区间进行二分减小范围 #include<bits/stdc++.h> using namespace std; double a,b,c,d; int s; double fc(double x){ return x*x*x*a+x*x*b+x*c+d...原创 2020-03-20 21:07:32 · 202 阅读 · 0 评论 -
P1577 切绳子
传送门 这道题跟木材加工很像,只不过这次是实数,输出保留小数(不四舍五入)后两位比较难 也可以先乘后除 改天spring和sscanf #include<bits/stdc++.h> using namespace std; const int maxn=1e4+10; int n,k; double a[maxn],num; char s[100]; bool check(dou...原创 2020-03-20 19:37:42 · 108 阅读 · 0 评论 -
P2440 木材加工
传送门 这题也是不难,就是当时题意有一个点没有想明白,就是sum可以大于k. 任何一个数/0,那么就会RT #include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; int n,a[maxn],k,num; bool check(int x){ int sum=0; for(int i=1;i<...原创 2020-03-20 17:19:41 · 93 阅读 · 0 评论 -
P1678 烦恼的高考志愿
传送门 这道题我的思路是将学校分数线进行排序,找出比考生分数线高的最小的分数线,和比考生低的最小的分数线,如果有相等的,那更好。 然后特判一下考生分数线比第一个学校的分数线还低,比最后一个学校分数线还高的情况 #include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; int n,m; int a[maxn...原创 2020-03-20 16:30:52 · 155 阅读 · 0 评论 -
P1873 砍树
砍树 这道题又做了一遍,感觉思路清晰很多,做的比较顺畅,将要砍的高度二分。 还有一个要注意,数据如果不确定又不卡时间,开long long. #include<bits/stdc++.h> using namespace std; const int maxn=1e6+10; typedef long long ll; int n,a[maxn],num; ll m; bool c...原创 2020-03-20 15:55:26 · 105 阅读 · 0 评论 -
P1102 A-B 数对
传送门 这题卡数据卡的。 这里有两种方法,如果纯暴力的话是n^2,肯定超时. 所以第一种是二分nlogn,还有一种是桶排序A-B=C,我们求出A的数量*B的数量,B怎么求呢,B=A-C. 二分 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=2e5+10; int n...原创 2020-03-20 15:30:28 · 131 阅读 · 0 评论 -
二分
文章目录二分查找面对整数时的万能二分(近似万能)砍树二分答案求最小值跳石头求最大值数列分段借教室 二分查找 面对整数时的万能二分(近似万能) int binary(int n) { int l = 1, r = maxn, ans = 0; while(l <= r) { int mid = (l + r) >> 1; ...原创 2020-01-31 12:48:58 · 82 阅读 · 0 评论 -
P2249 【深基13.例1】查找
传送门 这道题是二分查找,找到第一个符合的数在序列的下标 可以用STL,在这里我手写一下 #include<bits/stdc++.h> using namespace std; const int maxn=1e6+10; int n,m,x; int a[maxn]; int binary(int l,int r,int x){ int mid,ans=0; while(l...原创 2020-03-20 14:40:00 · 702 阅读 · 0 评论