Main » 2013 September 29 » [NOIP2010模拟赛]士兵
2:48 PM [NOIP2010模拟赛]士兵 |
搬运问题及相对位移#include<cstdio> #include<cstdlib> #include<cstring> #include<set> #include<algorithm> #include<map> #include<vector> #include<queue> #include<iostream> #include<string> #include<cmath> #define N 100010 #define FOR(i,a,b) for(i=(a);i<=(b);i++) #define ROF(i,a,b) for(i=(a);i>=(b);i--) typedef long long LL; using namespace std; int x[N],y[N]; int main() { int n,i; scanf("%d",&n); FOR(i,1,n) scanf("%d %d",&x[i],&y[i]); sort(y+1,y+1+n); int p=n/2+1; int ans=0; FOR(i,1,n) ans+=abs(y[i]-y[p]); sort(x+1,x+1+n); FOR(i,1,n) x[i]-=i-1; sort(x+1,x+1+n); FOR(i,1,n) ans+=abs(x[i]-x[p]); printf("%d\n",ans); } |
|
Total comments: 0 | |