马拉松

#include<iostream>
using namespace std;
const int N = 1e5 + 10;
pair<int,int>a[N];
#define x first
#define y second
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i].x >> a[i].y;
    }
    int mx = 0;
    int ans = 0;
    int j;
    for(int i = 2; i <= n ; i ++)
    {
      int d = abs(a[i].x - a[i - 1].x) + abs(a[i].y - a[i - 1].y) +abs(a[i + 1].x - a[i].x) + abs(a[i + 1].y - a[i].y)- abs(a[i + 1].x - a[i - 1].x) - abs(a[i + 1].y - a[i - 1].y); 
     if(d >= mx){
        mx = d;
        j = i;
        }
    }
    a[j].x = a[j - 1].x, a[j ].y = a[j - 1].y;
    for(int i = 2; i <= n; i ++)
    {
      ans += abs(a[i].x - a[i - 1].x) + abs(a[i].y - a[i - 1].y);
    }
    cout <<ans<<endl;
}
全部评论

相关推荐

强大的马里奥:不太可能,我校计算机硕士就业率99%
点赞 评论 收藏
分享
06-20 17:42
东华大学 Java
凉风落木楚山秋:要是在2015,你这简历还可以月入十万,可惜现在是2025,已经跟不上版本了
我的简历长这样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务