指数爆炸
一张厚度为1mm的纸,对折多少次,可超过地球到月球的距离(39万公里)?
对折10次之后达到1.024米;
对折20次后超过1km;
对折30次后超过1000km;
对折39次超过了39万公里;
只有39次;想象中应该是巨多次;这就是指数爆炸原理,用途很多,自己研究;
据说二分查找法是根据这个来的;
下面来做一下二分查找法程序;
#include<stdio.h>
#include<stdlib.h>
#define N 100
int a[N], num = 441, cnt = 0;
void init()
{
int i, j, t;
for (i = 0; i<N; i++)
{
a[i] = rand() % 900 + 100;
}
for (i = 0; i<N - 1; i++)
for (j = i + 1; j<N; j++)
if (a[i]>a[j])
{
t = a[i]; a[i] = a[j]; a[j] = t;
}
for (i = 0; i<N; i++)
{
printf("%4d", a[i]);
if ((i + 1) % 10 == 0)
printf("\n");
}
}
int find(int s, int e)
{
int m;
cnt++;
if (