1 条题解

  • 0
    @ 2025-9-10 9:00:38

    C :

    #include <stdio.h>
    #include <math.h>
    #define hypot(x,y) sqrt((x)*(x)+(y)*(y))
    
    double x[100], y[100];
    int N;
    
    double test(double xx, double yy) {
       double tot = 0;
       int i;
       for (i=0;i<N;i++) {
          tot += hypot(x[i]-xx,y[i]-yy);
       }
       return tot;
    }
    
    main(){
       int i,j,k;
       double xx,yy,delta;
    
       scanf("%d",&N);
       for (i=0;i<N;i++) scanf("%lf%lf",&x[i],&y[i]);
       
       xx = 5000;
       yy = 5000;
    
       for (delta=5000;delta > .0001;delta *=.9) {
          if (test(xx,yy+delta) < test(xx,yy)) yy+=delta;
          if (test(xx,yy-delta) < test(xx,yy)) yy-=delta;
          if (test(xx+delta,yy) < test(xx,yy)) xx+=delta;
          if (test(xx-delta,yy) < test(xx,yy)) xx-=delta;
       }
       printf("%0.0lf\n",test(xx,yy));
    }
    
    
    • 1

    信息

    ID
    3597
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者