标签:
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K (Java/Others)
Total Submission(s): 3359 Accepted Submission(s):
1083
#include <cmath> #include <queue> #include <cstdio> #include <cstring> #define N 3001 const int INF = 0x3f3f3f3f; using namespace std; int Nx, Ny, dis; int Mx[N], My[N], dx[N], dy[N], vis[N], map[N][N]; struct condit{ double x, y, V; }num[N], Sz[N]; bool Dfs(int u){ for(int v = 0; v < Ny; v++) if(!vis[v] && map[u][v] && dy[v] == dx[u] + 1){ vis[v] = 1; if(My[v] != -1 && dy[v] == dis) continue; if(My[v] == -1|| Dfs(My[v])){ My[v] = u; Mx[u] = v; return 1; } } return 0; } bool Search(){ queue<int> Q; dis = INF; memset(dx, -1, sizeof(dx)); memset(dy, -1, sizeof(dy)); for(int i = 0; i < Nx; i++) if(Mx[i] == -1){ Q.push(i); dx[i] = 0; } while(!Q.empty()){ int u = Q.front(); Q.pop(); if(dx[u] > dis) break; for(int v = 0; v < Ny; v++) if(map[u][v] && dy[v] == -1){ dy[v] = dx[u] + 1; if(My[v] == -1) dis = dy[v]; else{ dx[My[v]] = dy[v] + 1; Q.push(My[v]); } } } return dis != INF; } int Maxmatch(){ int res = 0; memset(Mx, -1, sizeof(Mx)); memset(My, -1, sizeof(My)); while(Search()){ memset(vis, 0, sizeof(vis)); for(int i = 0; i < Nx; i++) if(Mx[i] == -1&& Dfs(i)) res++; } return res; } double Count(condit a, condit b){ double c = a.x - b.x; double d = a.y - b.y; return sqrt(c*c+d*d); } int main(){ int t, Q = 1; scanf("%d", &t); while(t--){ //memset(dis, 0, sizeof(dis)); memset(map, 0, sizeof(map)); int n, m, Vt; scanf("%d", &Vt); scanf("%d", &m); for(int i = 0; i < m; i++) scanf("%lf%lf%lf", &num[i].x, &num[i].y, &num[i].V); scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%lf%lf", &Sz[i].x, &Sz[i].y); Nx = m; Ny = n; for(int i = 0; i < m; i++) for(int j = 0; j < n; j++){ if(Count(num[i], Sz[j])/num[i].V <= Vt) map[i][j] = 1; } printf("Scenario #%d:\n%d\n\n", Q++, Maxmatch()); } return 0; }
hdoj2389--Rain on your Parade(二分图HK算法)
标签:
原文地址:http://www.cnblogs.com/fengshun/p/5062108.html