250pt:

直接枚举跳过的位置求和即可。

int n,m; 
int ABS(int a) 
{ 
    if (a < 0) return (-a); 
    else return a; 
} 
class FoxAndSightseeing 
{ 
        public: 
        int getMin(vector <int> p) 
        { 
            n = p.size(); 
            int ans = 0; 
            for (int i = 1; i < n - 1; ++i) 
            { 
                int s = p[0]; 
                int tmp = 0; 
                for (int j = 1; j < n; ++j) 
                { 
                    if (j == i) continue; 
                    tmp += ABS(p[j] - s); 
                    s = p[j]; 
                } 
                if (ans == 0 || ans > tmp) ans = tmp; 
            } 
            return ans; 
        } 


}; 
View Code

相关文章:

  • 2021-08-22
  • 2021-07-09
  • 2021-05-27
  • 2021-10-05
  • 2022-02-16
  • 2022-02-24
  • 2021-07-30
  • 2022-12-23
猜你喜欢
  • 2021-10-06
  • 2021-08-12
  • 2021-06-29
  • 2021-12-22
  • 2021-08-27
  • 2021-11-04
  • 2022-01-11
相关资源
相似解决方案