为什么爬山只能拿89
查看原帖
为什么爬山只能拿89
649095
幻想繁星NM 猫猫可爱楼主2023/5/30 19:35
#include<bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &t) {
    t=0;char c=getchar();long long f=1;
    while(!isdigit(c)) {if(c=='-') f=-f;c=getchar();}
    while(isdigit(c)) t=(t<<3)+(t<<1)+(c^'0'),c=getchar();
    t*=f;
}
template <typename T, typename ... Args> inline void read(T &t,Args&... args){read(t);read(args...);}
template <typename T> inline void write(T x,char c='\0'){
    if(x<0) x=-x,putchar('-');
    if(x>9) write(x/10);
	putchar(x%10+'0');
	if(c!='\0') putchar(c);
}
inline long long read()
{
	long long t=0,f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-') f=-f;c=getchar();}
    while(isdigit(c)) t=(t<<3)+(t<<1)+(c^'0'),c=getchar();
    return t*f;
}
int n,x[10005],y[10005],w[10005];
double ansx,ansy;
int main()
{
  	n=read();
 	for(int i=1;i<=n;i++)
  	{
    	read(x[i],y[i],w[i]);
    	ansx+=x[i];
		ansy+=y[i];
  	}
  	ansx/=n;
  	ansy/=n;
  	for(double t=1412;t>=1e-9;t*=0.97)
  	{
    	double nowx=0,nowy=0;
    	for(int i=1;i<=n;i++)
		{
      		double dx=x[i]-ansx,dy=y[i]-ansy;
      		double dis=sqrt(dx*dx+dy*dy);
      		nowx+=(x[i]-ansx)*w[i]/dis;
      		nowy+=(y[i]- ansy)*w[i]/dis;
    	}
    	ansx+=nowx*t;
		ansy+=nowy*t;
  	}
  	printf("%.3lf %.3lf",ansx,ansy);
  	return 0;
}

2023/5/30 19:35
加载中...