题意:有 r 个人并知道他们的坐标和他们的速度,有 a 个目的地也知道坐标,规定时间为 t,求能到达目的地的最多人数(当然一个目的地只能被一个人占领)。
题解:核心算法 -> 匈牙利算法
CODE:
/* Author: JDD PROG: vijos1212 Way Selection DATE: 2015.9.28 */#include <cstdio> #include <cstring> #include <cmath> #define REP(i, s, n) for(int i = s; i <= n; i ++) #define REP_(i, s, n) for(int i = n; i >= s; i --) #define MAX_N 1005using namespace std;int r, a, t; double x[MAX_N], y[MAX_N]; double u[MAX_N], v[MAX_N], c[MAX_N];inline void init() {scanf("%d%d%d", &r, &a, &t);REP(i, 1, a) scanf("%lf%lf", &x[i], &y[i]);REP(i, 1, r) scanf("%lf%lf%lf", &u[i], &c[i], &v[i]); }bool map[MAX_N][MAX_N], used[MAX_N]; int G[MAX_N], ans = 0;bool find(int x) {REP(i, 1, a){if(!used[i] && map[x][i]){used[i] = 1;if(!G[i] || find(G[i])){G[i] = x;return 1;}}}return 0; }inline double dis(double x1, double y1, double x2, double y2) {return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }inline void doit() {memset(map, 0, sizeof(map));REP(i, 1, r) REP(j, 1, a){if(v[i] * t >= dis(u[i], c[i], x[j], y[j]))map[i][j] = 1;}//REP(i, 1, r) REP(j, 1, a) printf("%d\n", map[i][j]);REP(i, 1, r){memset(used, 0, MAX_N);if(find(i)) ans ++;}printf("%d\n", ans); }int main() {init();doit();return 0; }