hdu 3750:guess game

题目分析:对N求折半查找的平均查找长度(ASL),数据结构都有学的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

#include <stdlib.h>
#include <string.h>
#include <math.
int ()
{

system("Color F0");
double ASL;
int i,j,n,a;
while (scanf("%d",&n)!=EOF)
{
ASL = 0;
for ( i=1,j=1,a=1; a<=n; i++)
{
ASL += i*j*1.0/n;
j *= 2;
a = a+j;
}
ASL = ASL + i*(j-a+n)*1.0/n;
printf("%.2fn",ASL);
}
return 0;
}