二分尺取
zy-yz
编程小白一只
展开
-
二分搜索算法
二分搜索(BinarySearch)是基于分治算法的一种搜索算法,最简单的版本是用来查找某个数是否在数组里 下面举个栗子说明一下~~ 输入:数组 a,下标从left至right,数字x 输出:若x在数组a中,就输出其下标,否则输出no answer 基本思想:1、首先数组是有序的(从小到大) 2、将x与数组中间值a[mid]比较 ...原创 2018-07-14 04:14:44 · 473 阅读 · 0 评论 -
二分法应用
一、最大化最小值 eg:poj 2456:疯牛 #include<stdio.h> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int maxn = 1e7 + 10; ll a[maxn]; ll n, c; //对距离进行...原创 2018-10-09 13:25:40 · 135 阅读 · 0 评论 -
codeforces279B
题意:求最长的连续子序列。。。 input 4 5 3 1 2 1 output 3 input 3 3 2 2 3 output 1 <法一>由于数据范围是(1 ≤ n ≤ 10^5; 1 ≤ t ≤ 10^9) ,不会超时,可以直接模拟,不会超时。 #include <stdio.h> #include <assert.h&...原创 2018-09-25 14:48:41 · 229 阅读 · 0 评论 -
codeforces600B
一个长度为n的数列a[],一个长度为m的数列b[],在a中查找小于等于b[i]的值 二分求解: #include <stdio.h> #include<iostream> #include<algorithm> #include<cmath> #include<math.h> using namespace std; cons...原创 2018-09-27 17:25:38 · 192 阅读 · 0 评论