C# 二分查询
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 二分查询
{
class Program
{
static void Main(string[] args)
{ int[] array = { 10, 20, 50, 6, 45, 10, 33, 25, 40, 5 }; Array.Sort(array); Console.Write("数组排序之后: ");
foreach (var i in array)
{
Console.Write(i + ",");
} Console.WriteLine();
int a = SearchFun(array, 45);
Console.WriteLine("找到的值:" + a); Console.Read();
} static int SearchFun(int [] array,int value)
{
int mid, low, high; low = 0;
high = array.Length - 1; while (low < high)
{
mid = (low + high) / 2; //数组从中间找
if (array[mid] == value)
return array[mid]; if (array[mid] > value) //数组中的值 大于 要找的值, 继续在数组下部分查询
high = mid - 1;
else
low = mid + 1; //数组中的值 大于 要找的值, 继续在数组上部分查询
} return -1; } }
}

C# 二分查询的更多相关文章
- 【洛谷P2894】Hotel 线段树+二分查询
题目大意:给定一个长度为 N 的序列,每个点有两种状态 1/0,表示占有和空闲,现支持 first-fit 查询是否有一段连续的长度为 X 的空闲子序列和区间赋值操作. 题解:get到了线段树新技能. ...
- codeforces 633D - Fibonacci-ish 离散化 + 二分查询
Fibonacci-ish Yash has recently learnt about the Fibonacci sequence and is very excited about it. He ...
- bzoj1257 数学整理二分查询
2013-11-15 21:55 原题传送门http://www.lydsy.com/JudgeOnline/problem.php?id=1257 要求求sigma k mod i(i<=n) ...
- 二分查询-leetcode
二分查找-leetcode /** * * 278. First Bad Version * * You are a product manager and currently leading a ...
- Light oj 1138 - Trailing Zeroes (III) (二分)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...
- noip 2012 借教室 (线段树 二分)
/* 维护区间最小值 数据不超int 相反如果long long的话会有一组数据超时 无视掉 ll int */ #include<iostream> #include<cstdio ...
- 编程内功修炼之数据结构—BTree(二)实现BTree插入、查询、删除操作
1 package edu.algorithms.btree; import java.util.ArrayList; import java.util.List; /** * BTree类 * * ...
- 湖南省第十一届大学生程序设计竞赛:Internet of Lights and Switches(HASH+二分+异或前缀和)
Internet of Lights and Switches Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 3 Solved: 3[Submit][ ...
- 【Codeforces549F】Yura and Developers [单调栈][二分]
Yura and Developers Time Limit: 20 Sec Memory Limit: 512 MB Description Input Output Sample Input 4 ...
随机推荐
- Linux进程实时监控 - htop
htop 是一个 Linux 下的交互式的进程浏览器,top的增强版 htop: 进入:htop 退出:按q键 常用操作: ...
- Ignatius and the Princess III --undo
Ignatius and the Princess III Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (J ...
- 开源中国安卓client源代码学习(一) 渐变启动界面
开源中国安卓client源代码学习(一) 渐变启动界面 准备学习安卓开发, 看到网上有人推荐开源中国安卓client的源代码, 说里面包括了大部分技术, 于是准备好好研究研究. 特开通此系列博客来记录 ...
- js中setTimeout/setInterval定时器用法示例
js中setTimeout(定时执行一次)和setInterval(间隔循环执行)用法介绍. setTimeout:在指定的毫秒数后调用指定的代码段或函数:setTimeout示例代码 functio ...
- CentOS LiveCD LiveDVD DVD 等版本的区别
1.CentOS系统镜像DVD有两个,安装系统只用到第一个镜像即CentOS-6.7-x86_64-bin-DVD1.iso,第二个镜像CentOS-6.7-x86_64-bin-DVD2.iso是系 ...
- 【转载】Python编程中常用的12种基础知识总结
Python编程中常用的12种基础知识总结:正则表达式替换,遍历目录方法,列表按列排序.去重,字典排序,字典.列表.字符串互转,时间对象操作,命令行参数解析(getopt),print 格式化输出,进 ...
- 02-大文件Copy(FileStream文件流类)
static void Main(string[] args) { string source = @"e:\1.exe";//要移动文件的路径 大文件 string target ...
- django: db howto - 2
继 django: db howto - 1 : 一 操作数据库的三种方式: [root@bogon csvt03]# python2.7 manage.py shell Python 2.7.5 ( ...
- nginx log日志分割
@echo offrem 备份并根据时间重命名错误日志文件set "cmdstr=move E:\nginx\logs\error.log E:\nginx\logs\error%date: ...
- Struts2 过滤器与拦截器
学习Struts2时,发现有过滤器和拦截器,他们貌似都是一样的功能,但是为什么会有2个不同的名称呢?肯定是有区别的,所以打算自己整理一下. 过滤器,是在java web中,你传入的request,re ...