
----二分搜索
欣君
追寻那如樱花般的绚烂
展开
-
51nod 1287 加农炮
二分+线段树的经典题目#includeusing namespace std;int num[100000];struct node{ int l,r; long long nsum;}segtree[300000];void build(int i,int l,int r){ segtree[i].l=l; segtree[i].r=r; if(l==r) {原创 2016-11-06 14:28:08 · 258 阅读 · 0 评论 -
51nod 1364 最大字典序排列
贪心+线段树+二分姿势有点问题。。加了快速读写才不T。。。。#includeusing namespace std;const int MAXN=100100;int a[MAXN],pos[MAXN];struct node{ int l,r; int nsum;}segtree1[MAXN<<2],segtree2[MAXN<<2];void build1(int原创 2016-12-08 00:27:18 · 291 阅读 · 0 评论 -
51nod 1421 最大MOD值
枚举mod,二分答案#includeusing namespace std;const int MAXN=1000100;int a[MAXN],sum[MAXN],mx;bool judge(int x,int limit){ for(int i=a[x];i<=mx;i+=a[x]) { if((sum[(i+a[x]-1>mx?mx+1:i+a[x]-1)]-sum原创 2016-12-07 20:58:51 · 346 阅读 · 0 评论 -
51nod 1686 第K大区间
二分答案,求解时,采用了容斥。#includeusing namespace std;const int MAXN=100100;int a[MAXN],b[MAXN];long long n;long long mul(long long x){ if(x<=0) return 0; return x*(x-1)/2;}long long cal(int x)转载 2016-11-24 01:38:19 · 359 阅读 · 0 评论 -
51nod 1460 连接小岛
贪心+二分。将桥的合法范围进行排序,二分查找对应的桥。#includeusing namespace std;const int MAXN=200200;struct seg{ long long mn,mx;}bdg[MAXN];bool cmp(seg s1,seg s2){ if(s1.mx!=s2.mx) return s1.mx<s2.mx; else原创 2016-11-20 02:13:53 · 255 阅读 · 0 评论 -
51nod 1112 KGold
宛如自己是一个智障。。。打错1个字母,调了一天。。。。二分找出第10000次超越发生的时间,然后N*N时间内计算答案。由于许多都会被continue,所以进行直线交的计算次数只有1W,不会超时。#includeusing namespace std;const int MAXN=10010;int n;struct preson{ int index,ordinal,m,s转载 2016-11-19 23:05:30 · 319 阅读 · 0 评论 -
51nod 1128 正整数分组 V2
二分下答案就好了。#includeusing namespace std;const int MAXN=50050;long long n,k;long long a[MAXN];bool judge(long long limit){ long long sum=1,now=0,i; for(i=1;i<=n;i++) { if(a[i]>limit) ret原创 2016-11-30 23:14:04 · 325 阅读 · 0 评论 -
51nod 1420 数袋鼠好有趣
贪心+二分能装进大袋鼠的小袋鼠,肯定是最小的那几个。所以二分枚举小袋鼠的数量即可。#includeusing namespace std;const int MAXN=500500;int n,a[MAXN];bool judge(int x){ for(int i=0,j=n-x;i<x;i++,j++) { if(a[i]+a[i]>a[j]) retu原创 2016-11-15 01:32:48 · 295 阅读 · 0 评论 -
51nod 1350 斐波那契表示
,我们简单列下前几组数据x 1 2 3 4 5 6 7 8 9 10 11 12 13 * * * * * *F(x) 1 1 1 2 1 2 2 1 2 2 2 3 1 G(x) 1 2 3 6 11原创 2016-11-15 00:22:59 · 653 阅读 · 0 评论 -
51nod 1422 沙拉酱前缀
记录所有操作以及操作结束后的数列长度。对于每个询问,二分查找对应的操作。如果查找到的操作种类为2,则继续向前二分查找,直到查找到的操作种类为1为止。时间复杂度O(N*log(N)*log(N))#includeusing namespace std;const int MAXN=100100;long long op[MAXN],pos[MAXN],l[MAXN],c[MAXN],原创 2016-11-14 21:12:49 · 282 阅读 · 0 评论 -
51nod 1243 排船的问题
这么一道简单题,居然因为2次看错题目被卡住了。。。二分一下就好。#includeusing namespace std;const int MAXN=50050;long long n,m,x;long long p[MAXN];bool judge(long long limit){ long long bef=x,i,dis; for(i=0;i<n;i++) {原创 2016-11-16 01:16:11 · 330 阅读 · 0 评论 -
51nod 1281 山峰和旗子
二分搜索标准题目。题目和我大一刚学C++时做到的一道题很想。。。现在想想老师真看得起我们。。。#includeusing namespace std;int a[50050],n;bool judge(int k){ if(k==0) return 1; int i,sum=0; for(i=1;i<n-1;i++) { if(a[i]>a[i-1]&&a[i]>a原创 2016-11-08 23:44:57 · 224 阅读 · 0 评论 -
51nod 1711 平均数
参考:http://blog.youkuaiyun.com/samjia2000/article/details/51778301#includeusing namespace std;const double eps=1e-6;const int MAXN=100100;double val[MAXN];long long a[MAXN];int n,num[MAXN];bool cm转载 2016-12-08 15:50:58 · 269 阅读 · 0 评论