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 ...
随机推荐
- 怎样把HTC G7的内存扩展到2GB
介绍 HTC G7的内部存储只有148M,两年前买它的时候,android应用大多比较小巧,148M已经足够用了.随着android版本的不断升级,应用变得越来越臃肿,G7也变得越来越吃力.就我个人而 ...
- 一个安全测试的CheckList
转自:http://hi.baidu.com/dontcry/item/90c2bc466558c217886d1075 不登录系统,直接输入登录后的页面的URL是否可以访问: 不登录系统,直接输入下 ...
- HDU 1853Cyclic Tour(网络流之最小费用流)
题目地址:pid=1853">HDU1853 费用流果然好奇妙. .还能够用来推断环...假设每一个点都是环的一部分并且每一个点仅仅能用到一次的话,那每一个点的初度入度都是1,这就能够 ...
- SOAP 简单对象访问协议
webService三要素 SOAP.WSDL(WebServicesDescriptionLanguage).UDDI(UniversalDescriptionDiscovery andIntegr ...
- ftp nfs samba比较
首先从字面意思上区分一下:1. FTP(文件传输协议)2. NFS(网络文件系统)3. samba 即smb(服务信息块)协议其中FTP 是TCP/IP协议栈所提供的一种子协议,该子协议具体可以实现在 ...
- Set Windows IP by Batch
netsh interface ip set address name="Local" static 192.168.1.55 255.255.255.0 192.168.1.1 ...
- jQuery animate easing使用方法
从jQuery API 文档中可以知道,jQuery自定义动画的函数.animate( properties [, duration] [, easing] [, complete] )有四个参数: ...
- jQuery下的显示和隐藏
因为太久没更新了,所以来放一点没意思的内容. 做的是jQuery框架的隐藏和显示,HTML如下: <ul> <li>1</li> <li>2</l ...
- Asp.Net WebAPI传递json对象、后台手动接收参数
1.前台代码 /* * 跨域请求Post * 1个对象参数,后台JObject接受 */ $.post(apiUrl.getOne("PostFourth"), { name: } ...
- .NET中使用GridView控件输入数据时出现“ Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"的问题
在.NET中使用GridView控件的在线编辑数据时,出现了“ Index was out of range. Must be non-negative and less than the size ...