一、Binary Search and it's use
二、Suppose you have 10000 Electronic circuits in hand. 
Now more than half of those circuits are good and rest are bad. There is only one way to find out if a circuit is good or bad. You have to compare the circuit with another circuit. Suppose you want to find out if circuit A is good or bad. You compare it with another circuit B. Now if B is a good circuit it will tell you the truth about A.
But if B is a bad circuit it's answer about a is not reliable. Write a function to find out one good circuit. 
第一道有点难
大家帮忙看下

解决方案 »

  1.   

    1、例:(C语言)方程式为:f(x) = 0,示例中f(x) = 1+x-x^3 使用示例: input a b e: 1 2 1e-5 solution: 1.32472 源码如下: #include <stdio.h> #include <stdlib.h> #include <math.h> #include <assert.h> double f(double x) { return 1+x-x*x*x; } int main() { double a = 0, b = 0, e = 1e-5; printf("input a b e: "); scanf("%lf%lf%lf", &a, &b, &e); e = fabs(e); if (fabs(f(a)) <= e) { printf("solution: %lg\n", a); } else if (fabs(f(b)) <= e) { printf("solution: %lg\n", b); } else if (f(a)*f(b) > 0) { printf("f(%lg)*f(%lg) > 0 ! need <= 0 !\n", a, b); } else { while (fabs(b-a) > e) { double c = (a+b)/2.0; if (f(a)* f ( c ) < 0) b = c; else a = c; } printf("solution: %lg\n", (a+b)/2.0); 

    return 0; 
    }
      

  2.   

    有1000个电路圈,一半以上是好的,其余的都是坏的。
    有一种方法可以查找A是个好的还是坏的
    用B去比较A,如果B是好的,则A是好的,如果B是坏的,则说明A是不可靠的
    写个函数,查找一个好的线圈
    意思应该是这么翻译的吧?
      

  3.   

    http://topic.csdn.net/u/20070919/13/5d17c977-7f88-44cb-95fb-543371e015e5.html