[JZOJ5775]【NOIP2008模拟】农夫约的假期
貌似是标程出了锅, 只有z=1的情况23333.
所以找x的中位数, y的中位数作为答案, 就完了。
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <queue> using namespace std; inline int read() { int res=0;char c=getchar();bool f=0; while(!isdigit(c)) {if(c=='-')f=1;c=getchar();} while(isdigit(c))res=(res<<3)+(res<<1)+(c^48),c=getchar(); return f?-res:res; } int n, m , z; int x[100005], y[100005], q[100005]; long long ans; int ansx, ansy; int main() { freopen("shuru.in", "r", stdin); freopen("shuru.out", "w", stdout); n = read(), m = read(), z = read(); for (register int i = 1 ; i <= m ; i ++) x[i] = read(), y[i] = read(), ans += (q[i] = read()); sort(x + 1, x + 1 + m); sort(y + 1, y + 1 + m); ansx = x[(m+1)/2], ansy = y[(m+1)/2]; for (register int i = 1 ; i <= m ; i ++) ans += abs(ansx - x[i]) + abs(ansy - y[i]); printf("%lld\n%d %d\n", ans, ansx, ansy); return 0; }