(Jizhong) 2189. Marathon

(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 N N cities, a cow from 1 1 Number City sequentially through N N cities, and finally to N N number of cities. But only cows think this is too boring, so it decided to skip a city which (but not skip 1 1 number and N N number change), such that it from 1 1 Number City began arriving N N minimum number of cities through which the total distance. Every city has a coordinate, from the city ( x 1 , Y 1 ) (x1, y1) to the city ( x 2 , Y 2 ) (x2, y2) a distance x 1 x 2 + Y 1 Y 2 |x1 - x2| + |y1 - y2|


Enter
a number of the first row N N , is the number of cities
on the next line N N each row two rows x , Y x, y , represent the coordinates of each city

Output
line a number a n s years , such that it from 1 1 Number City began to skip a certain city, arrival N N 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 40 40 % of the data, N < = 1000 N <= 1000 .
• For 100 100 % of the data, 3 < = N < = 1 0 5 1 0 3 < = x < = 1 0 3 1 0 3 < = y < = 1 0 3 3 <= N <= 10^5,-10^3 <= x <= 10^3,-10^3 <= y <= 10^3


Tips
skip 2 2 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);
}
Published 119 original articles · won praise 8 · views 4930

Guess you like

Origin blog.csdn.net/kejin2019/article/details/104685142