HDU 2389 Rain on your Parade(Hopcroft_Carp Algorithm)
2016-05-04 16:33
441 查看
题目链接:
HDU 2389 Rain on your Parade
HDU 2389 Rain on your Parade
#include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <string> #include <algorithm> #include <climits> #include <queue> using namespace std; const int MAX_N = 3010; int T, n, m, total, dis, cases = 0; double t, x[MAX_N], y[MAX_N], v[MAX_N]; int matchx[MAX_N], matchy[MAX_N], head[MAX_N]; int disx[MAX_N],disy[MAX_N], vis[MAX_N]; struct Edge{ int to, next; Edge () {} Edge(int _to, int _next) : to(_to), next(_next) { } }edge[MAX_N*MAX_N]; inline void init() { total=0; memset(matchx,-1,sizeof(matchx)); memset(matchy,-1,sizeof(matchy)); memset(head,-1,sizeof(head)); } inline void AddEdge(int from, int to) { edge[total].to = to; edge[total].next = head[from]; head[from] = total++; } inline bool bfs() { dis = INT_MAX; memset(disx, -1, sizeof(disx)); memset(disy, -1, sizeof(disy)); queue<int> que; for(int i = 0; i < n; i++){ if(matchx[i] == -1){ que.push(i); disx[i] = 0; } } while(!que.empty()){ int u = que.front(); que.pop(); if( disx[u] > dis) break; for(int i = head[u]; i != -1; i = edge[i].next){ int v = edge[i].to; if( disy[v] == -1){ disy[v] = disx[u] + 1; if(matchy[v] == -1) dis = disy[v]; else { disx[matchy[v]] = disy[v] + 1; que.push(matchy[v]); } } } } return dis != INT_MAX; } inline bool dfs(int u) { for(int i = head[u]; i != -1; i = edge[i].next){ int v = edge[i].to; if(!vis[v]){ vis[v] = 1; if(matchy[v] != -1 && disy[v] == dis) continue; if(matchy[v] == -1 || dfs(matchy[v]) ){ matchy[v] = u; matchx[u] = v; return true; } } } return false; } inline int Hopcroft_Carp() { int ans = 0; while( bfs() ){ memset(vis, 0, sizeof(vis)); for(int i = 0; i < n; i++){ if(matchx[i] == -1 && dfs(i)) ans++; } } return ans; } int main() { freopen("hdu2389.in","r",stdin); scanf("%d", &T); while(T-- > 0){ init(); scanf("%lf%d", &t, &n); for(int i = 0; i < n; i++){ scanf("%lf%lf%lf",&x[i], &y[i], &v[i]); } scanf("%d",&m); for(int i = 0; i < m; i++){ double tmpx, tmpy; scanf("%lf%lf",&tmpx, &tmpy); for(int j = 0; j < n; j++){ double tmp = sqrt((tmpx - x[j]) * (tmpx - x[j]) + (tmpy - y[j]) * (tmpy - y[j])); if(v[j] * t >= tmp){ //printf("j = %d i = %d\n",j, i); AddEdge(j,i); } } } int ans = Hopcroft_Carp(); printf("Scenario #%d:\n%d\n\n",++cases,ans); } return 0; }
相关文章推荐
- 【HDU 5366】The mook jong 详解
- 【HDU 2136】Largest prime factor 详细图解
- 【HDU 1568】Fibonacci 数学公式 详解
- HDU 1568
- HDU1290
- HDU1568(Fobonacci公式)
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)
- HDU 1405
- HDU 1297
- hdu 1205
- hdu 2087
- hdu 1016
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- HDU 5592 ZYB's Premutation 线段树(查找动态区间第K大)
- HDU 5240 Exam (好水的题)
- HDU5237 Base64 大模拟
- HDU 1000
- HDU 1001
- HDU 1016 Prime Ring Problem
- HDU 1017 A Mathematical Curiosity