(File IO): input: marathon.in output: marathon.out
time limit: 1000 ms space constraints: 262144 KB specific restrictions
Goto ProblemSet
Title Description
There on the map
cities, a cow from
Number City sequentially through
cities, and finally to
number of cities. But only cows think this is too boring, so it decided to skip a city which (but not skip
number and
number change), such that it from
Number City began arriving
minimum number of cities through which the total distance. Every city has a coordinate, from the city
to the city
a distance
。
Enter
a number of the first row
, is the number of cities
on the next line
each row two rows
, represent the coordinates of each city
Output
line a number
, such that it from
Number City began to skip a certain city, arrival
number of cities through which the smallest total distance
Sample input
. 4
0 0
. 8. 3
. 11 -1
10 0
Sample output
14
Data range limit
• For
% of the data,
.
• For
% of the data,
。
Tips
skip
Hao City
Problem-solving ideas
direct violence enumeration. . .
Code
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;
int n,a[100010][3],n,minn,ans,t;
int main(){
freopen("marathon.in","r",stdin);
freopen("marathon.out","w",stdout);
scanf("%d",&n);
minn=2147483647;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&a[i][1],a[i][2]);
t=t+abs(a[i-1][1]-a[i][1])+abs(a[i-1][2]-a[i][2]);
}
for(int i=1;i<=n;i++)
{
ans=s-(abs(a[i][1]-a[i-1][1])+abs(a[i][2]-a[i-1][2]))-(abs(a[i][1]-a[i+1][1])+abs(a[i][2]-a[i+1][2]))+(abs(a[i-1][1]-a[i+1][1])+abs(a[i-1][2]-a[i+1][2]));
if(ans<minn)
minn=ans;
}
printf("%d",minn);
}