GDUT_ winter training solution to a problem report _ topic I_K personal problem solution to a problem report

GDUT_ winter training solution to a problem report _ topic I_K personal problem solution to a problem report

topic:

Josephina is a clever girl and addicted to Machine Learning recently. She
pays much attention to a method called Linear Discriminant Analysis, which
has many interesting properties.
In order to test the algorithm’s efficiency, she collects many datasets.
What’s more, each data is divided into two parts: training data and test
data. She gets the parameters of the model on training data and test the
model on test data. To her surprise, she finds each dataset’s test error curve is just a parabolic curve. A parabolic curve corresponds to a quadratic function. In mathematics, a quadratic function is a polynomial function of the form f(x) = ax2 + bx + c. The quadratic will degrade to linear function if a = 0.

It’s very easy to calculate the minimal error if there is only one test error curve. However, there are several datasets, which means Josephina will obtain many parabolic curves. Josephina wants to get the tuned parameters that make the best performance on all datasets. So she should take all error curves into account, i.e., she has to deal with many quadric functions and make a new error definition to represent the total error. Now, she focuses on the following new function’s minimum which related to multiple quadric functions. The new function F(x) is defined as follows: F(x) = max(Si(x)), i = 1…n. The domain of x is [0, 1000]. Si(x) is a quadric function. Josephina wonders the minimum of F(x). Unfortunately, it’s too hard for her to solve this problem. As a super programmer, can you help her?

Input

The input contains multiple test cases. The first line is the number of cases T (T < 100). Each case begins with a number n (n ≤ 10000). Following n lines, each line contains three integers a (0 ≤ a ≤ 100), b (|b| ≤ 5000), c (|c| ≤ 5000), which mean the corresponding coefficients of a quadratic function.

Output

For each test case, output the answer in a line. Round to 4 digits after the decimal point.

Sample Input

2
1
2 0 0
2
2 0 0
2 -4 2

Sample Output

0.0000
0.5000

This problem should be bare-third template, just let me practice this dish chicken-third, first meaning of the questions, so many quadratic function, there is a function F (X) is called at x, take all quadratic function of the maximum value, then we can get a picture F (x), find F (x) minimum

Ideas steps:

1. drawing, we can see two very narrow quadratic function, they can form a slit, able to cover almost all function values, but there are likely to be across in the past, in short, we can get a conclusion by drawing: F (x) function necessarily a single peak function, with up to a point not lead up to a minimum point there is a minimum point, in short, is a function of a single peak, where the minimum point is our answer.

2. The first step in speaking short step to actually draw this conclusion requires a certain image processing capabilities, but also not particularly difficult.

-------------half and three different, two points are given: this side to meet the conditions, then the answer must be in the other side, and then continue to narrow the scope, the maximum / minimum point to meet the conditions of the draw but one-third different.
------------ third for seeking the minimum or maximum value within a range, three ideas can be so described:

Third: in a period range: with L, R, to find among them two points, this time the (l, r) is divided into three portions, there are two sub-method; taken three and four portions in three part

-> take part in four three What does it mean? These two set points mid1, and MID2
MID1 = (R & lt + L) / 2, MID2 = (R & lt MID +) / 2 or (L + MID) / 2,
-> triplicate is easy to understand: mid1 = (L 2 + R & lt) /. 3 = ;;; MID2 (R & lt L + 2) /. 3

Both are possible, see the personal wording;
third is to determine the next step:
to a convex function as an example, to find the minimum (two big middle small)
three cases:
1. If the answer to the left MID1, then F (mid1) <F (mid2)
2. If the answer between mid1 and mid2, then there are F (mid1) <F (mid2 ) or F (mid1)> F (mid2)
3. If the answer to the right mid2, there are F (mi1)> F (mid2)
we classify this:
If F (mid1) <F (mid2 ), then the answer in mid2 left, so r = mid2 can;
if F (mid1)> F (mid2 ), then the answer the right mid1, l = mid1 can make;

Then while statement is the end of the floating-point binary (rl <eds) {}
This is the accuracy eds,

Code:

#define ULL unsigned long long
using namespace std;
typedef struct element
{
	double a,b,c;
}ele;

ele all[10010];

int t,n;
double f(int i,double x)
{//fi(x)的求值函数
	return all[i].a*x*x+all[i].b*x+all[i].c;
}
double F(double x)
{
	double _MAX=f(0,x);
	for(int time=1;time<n;time++)
	{
		if(f(time,x)>_MAX)_MAX=f(time,x);
	}
	return _MAX;
}

int main()
{
	scanf("%d",&t);
		for(int time=0;time<t;time++)
		{
			scanf("%d",&n);
			for(int time1=0;time1<n;time1++)
			{
				scanf("%lf %lf %lf",&all[time1].a,&all[time1].b,&all[time1].c);
			}
			double l=0;
			double r=1000;
			while(r-l>1e-9)
			{
				double mid1=(l*2+r)/3;
				double mid2=(l+r*2)/3;

				if(F(mid1)<F(mid2))r=mid2;
				else l=mid1;
			}
			printf("%.4f\n",F(l));
		}
    return 0;
}
发布了9 篇原创文章 · 获赞 0 · 访问量 198

Guess you like

Origin blog.csdn.net/DevourPower/article/details/103965177