Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.3 kB
4
Indexable
Never
#include<iostream>

using namespace std;

int coor[11],m[11];
int t,n;
double result;

double abs(double x, double y){
	return (x>y)? (x-y) : (y-x);
}

int compare(int st,int end, double curpoint){
	double totalleft=0; double totalright=0;
	for(int i=st;i>=1;i--){
		totalleft+= m[i]/((curpoint-coor[i])*(curpoint-coor[i]));
	}
	for(int i=end;i<=n;i++){
		totalright+= m[i]/((curpoint-coor[i])*(curpoint-coor[i]));
	}
	if(abs(totalleft,totalright)<=0.000000001) return 0;
	return (totalleft<totalright)? -1 : 1;
}

double findpointofbalance(int st, int end, double left, double right){
	double center=(left+right)/2;
	int check=compare(st,end,center);
	if(check==0){
		return center;
	}
	else if(check==1){
		return findpointofbalance(st,end,center,right);
	}
	else{
		return findpointofbalance(st,end,left,center);
	}
}

int main(){
	//freopen("input.txt","r",stdin);
	for(int tc=1;tc<=10;tc++){
		cin >> n;
		for(int i=1;i<=n;i++) cin >> coor[i];
		for(int i=1;i<=n;i++) cin >> m[i];
		cout << "#" << tc << " " ;
		for(int i=1;i<n;i++){
			result=findpointofbalance(i,i+1,coor[i],coor[i+1]);
			cout << fixed;
			cout.precision(10);
			cout << result << " ";
		}
		cout << endl;
	}



	return 0;
}
Leave a Comment