106E - Space Rescuers - CodeForces Solution


geometry ternary search *2100

Please click on ads to support us..

C++ Code:

// Hydro submission #63e1e82c9ae2a264272990b4@1675749420853
#include<bits/stdc++.h>
using namespace std;
int n;
double px[105],py[105],pz[105];
double ansx,ansy,ansz;
double calc3(){
	double res=0;
	for(int i=1;i<=n;i++)res=max(res,(ansx-px[i])*(ansx-px[i])+(ansy-py[i])*(ansy-py[i])+(ansz-pz[i])*(ansz-pz[i]));
	return res;
}
double calc2(){
	double l=-1e4,r=1e4;
	while(l+1e-7<=r){
		double mid1=l+(r-l)/3,mid2=r-(r-l)/3;
		ansz=mid1;
		double val1=calc3();
		ansz=mid2;
		double val2=calc3();
		if(val1>val2)l=mid1;
		else r=mid2;
	}
	ansz=l;
	return calc3();
}
double calc1(){
	double l=-1e4,r=1e4;
	while(l+1e-7<=r){
		double mid1=l+(r-l)/3,mid2=r-(r-l)/3;
		ansy=mid1;
		double val1=calc2();
		ansy=mid2;
		double val2=calc2();
		if(val1>val2)l=mid1;
		else r=mid2;
	}
	ansy=l;
	return calc2();
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lf%lf%lf",&px[i],&py[i],&pz[i]);
	double l=-1e4,r=1e4;
	while(l+1e-7<=r){
		double mid1=l+(r-l)/3,mid2=r-(r-l)/3;
		ansx=mid1;
		double val1=calc1();
		ansx=mid2;
		double val2=calc1();
		if(val1>val2)l=mid1;
		else r=mid2;
	}
	ansx=l;
	calc1();
	printf("%.6lf %.6lf %.6lf\n",ansx,ansy,ansz);
	return 0;
}


Comments

Submit
0 Comments
More Questions

1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64
755B - PolandBall and Game
808B - Average Sleep Time
1515E - Phoenix and Computers
1552B - Running for Gold
994A - Fingerprints
1221C - Perfect Team
1709C - Recover an RBS
378A - Playing with Dice
248B - Chilly Willy
1709B - Also Try Minecraft
1418A - Buying Torches
131C - The World is a Theatre
1696A - NIT orz
1178D - Prime Graph
1711D - Rain
534A - Exam