luchapdan

 avatar
quoc14
c_cpp
a month ago
1.3 kB
0
Indexable
Never
caidat
#include <iostream>
#include <stdio.h>
2
1 2 1 1
2
1 2 1 1000
2
457 468 333 321
3
1 2 3 1 2 1
4
2 3 5 7 3 2 7 5
5
3 11 12 19 29 542 661 450 521 366	
6
42 75 88 94 113 144 669 551 355 344 294 155
7
62 86 279 323 363 516 579 810 749 736 297 136 107 52
8
10 34 64 73 93 97 101 122 466 463 441 373 315 292 225 83
10
9 14 38 39 48 73 179 190 207 302 560 497 640 722 437 259 449 470 709 520

using namespace std;
int a[102];
int w[104];
int n;

double f(double m1, double d)
{
	return m1/(d*d);
}

double abss(double aa)
{
	if (aa<0) return -aa;
	else return aa;
}
double binary(int i, int j, double L, double R)
{
	double mid = (L+R)/2;
	double trai = 0;
	double phai = 0;
	for (int k = 1; k<=i; k++)
		trai += f(w[k], mid-a[k]);

	for (int k = i+1; k<=n; k++)
		phai += f(w[k], a[k]-mid);

	if (abss(trai-phai) <= 0.000000001) return mid;
	if (trai > phai) return binary(i,j,mid, R);
	else return binary(i,j,L, mid);
}
int main()
{
	//freopen("input.txt","r",stdin);
	
	for (int tc=1; tc<=10; tc++)
	{
		cin >> n;
		for (int i=1; i<=n; i++)
			cin >> a[i];

		for (int i=1; i<=n; i++)
			cin >> w[i];
		cout << "#" <<tc;
		for (int i=1; i<=n-1; i++)
			printf(" %.10f", binary(i, i+1, a[i], a[i+1]));
		cout << endl;
	}

	return 0;
}
Leave a Comment