#include <iostream>
using namespace std;
double w = 0.001;
double r = 0.0001;
double a = 1.0,b = 1.0;
double f(double x)
{
double res;
res = a*x + b;
return res;
}
void df(double x,double y)
{
double t1,t2;
int n;
while( max( (f(x) - y) , (y - f(x)) ) > w )
{
cout << max( (f(x)-y) , (y-f(x)) ) << " " << a << " " << b << endl;
if(f(x) < y)
{
n = 1.0;
}
else
{
n = -1.0;
}
t1 = max( ((f(x)+x*r*n) - y) , (y - (f(x)+x*r*n)) );
t2 = max( ((f(x)+r*n) - y) , (y - (f(x)+r*n)) );
if(t1 < t2)
{
a += r*n;
}
else
{
b += r*n;
}
}
cout << "...OK" << endl;
}
int main()
{
string s;
double x,y;
while(true)
{
cin >> s;
if(s == "in")
{
cin >> x >> y;
df(x,y);
}
else if(s == "out")
{
cin >> x;
cout << f(x) << endl;
}
}
return 0;
}
一个副本而已