HDU2389-Rain on your Parade-二分图匹配-ISAP

裸二分图匹配

  1 /*--------------------------------------------------------------------------------------*/
  2
  3 #include <algorithm>
  4 #include <iostream>
  5 #include <cstring>
  6 #include <ctype.h>
  7 #include <cstdlib>
  8 #include <cstdio>
  9 #include <vector>
 10 #include <string>
 11 #include <queue>
 12 #include <stack>
 13 #include <cmath>
 14 #include <set>
 15 #include <map>
 16
 17 //debug function for a N*M array
 18 #define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++) 19 {for(int j=0;j<(M);j++){ 20 printf("%d",G[i][j]);}printf("\n");}
 21 //debug function for int,float,double,etc.
 22 #define debug_var(X) cout<<#X"="<<X<<endl;
 23 #define LL long long
 24 const int INF = 0x3f3f3f3f;
 25 const LL LLINF = 0x3f3f3f3f3f3f3f3f;
 26 /*--------------------------------------------------------------------------------------*/
 27 using namespace std;
 28
 29 int N,M,T,t;
 30 const int maxn = 6010;
 31 vector <int> G[maxn];
 32 int uN;
 33 int Mx[maxn],My[maxn];
 34 int dx[maxn],dy[maxn];
 35 int dis;
 36 bool used[maxn];
 37 bool SearchP()
 38 {
 39     queue<int> Q;
 40     dis = INF;
 41     memset(dx,-1,sizeof dx);
 42     memset(dy,-1,sizeof dy);
 43     for(int i=1;i<=uN;i++)
 44     {
 45         if(Mx[i] == -1)
 46         {
 47             Q.push(i);
 48             dx[i] = 0;
 49         }
 50     }
 51     while(!Q.empty())
 52     {
 53         int u = Q.front();
 54         Q.pop();
 55         if(dx[u] > dis) break;
 56         int sz = G[u].size();
 57         for(int i=0;i<sz;i++)
 58         {
 59             int v = G[u][i];
 60             if(dy[v] == -1)
 61             {
 62                 dy[v] = dx[u] + 1;
 63                 if(My[v] == -1) dis = dy[v];
 64                 else
 65                 {
 66                     dx[My[v]] = dy[v] + 1;
 67                     Q.push(My[v]);
 68                 }
 69             }
 70         }
 71     }
 72     return dis != INF;
 73 }
 74 bool DFS(int u)
 75 {
 76     int sz = G[u].size();
 77     for(int i=0;i<sz;i++)
 78     {
 79         int v = G[u][i];
 80         if(!used[v] && dy[v] == dx[u]+1)
 81         {
 82             used[v] = true;
 83             if(My[v] != -1 && dy[v] == dis) continue;
 84             if(My[v] == -1 || DFS(My[v]))
 85             {
 86                 My[v] = u;
 87                 Mx[u] = v;
 88                 return true;
 89             }
 90         }
 91     }
 92     return false;
 93 }
 94
 95 int MaxMatch()
 96 {
 97     int res = 0;
 98     memset(Mx,-1,sizeof Mx);
 99     memset(My,-1,sizeof My);
100     while(SearchP())
101     {
102         memset(used,false,sizeof used);
103         for(int i=1;i<=uN;i++) if(Mx[i] == -1 && DFS(i))
104             res++;
105     }
106     return res/2;
107 }
108
109 typedef pair<int,int> point;
110 vector <point> gst;
111 int v[maxn];
112
113 int main()
114 {
115     scanf("%d",&T);
116     int cas = 0;
117     while(T--)
118     {
119         scanf("%d%d",&t,&N);
120         for(int i=0;i<maxn;i++) G[i].clear();
121
122         gst.clear();
123         for(int i=1,x,y,s;i<=N;i++)
124         {
125             scanf("%d%d%d",&x,&y,&s);
126             gst.push_back(make_pair(x,y));
127             v[i] = s;
128         }
129         scanf("%d",&M);
130         uN = N+M;
131         for(int i=1,x,y;i<=M;i++)
132         {
133             scanf("%d%d",&x,&y);
134             for(int g=0;g<gst.size();g++)
135             {
136                 if((x-gst[g].first)*(x-gst[g].first)+(y-gst[g].second)*(y-gst[g].second) <= t*v[g+1]*t*v[g+1])
137                 {
138                     G[g+1].push_back(i+N);
139                     G[i+N].push_back(g+1);
140                     //printf("link:[%d,%d]\n",g+1,i+N);
141                 }
142             }
143         }
144         printf("Scenario #%d:\n%d\n\n",++cas,MaxMatch());
145     }
146 }
时间: 2024-10-08 07:47:03

HDU2389-Rain on your Parade-二分图匹配-ISAP的相关文章

hdu-2389.rain on your parade(二分匹配HK算法)

Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Others)Total Submission(s): 6752    Accepted Submission(s): 2117 Problem Description You’re giving a party in the garden of your villa by the sea. The p

Hdu 3289 Rain on your Parade (二分图匹配 Hopcroft-Karp)

题目链接: Hdu 3289 Rain on your Parade 题目描述: 有n个客人,m把雨伞,在t秒之后将会下雨,给出每个客人的坐标和每秒行走的距离,以及雨伞的位置,问t秒后最多有几个客人可以拿到雨伞? 解题思路: 数据范围太大,匈牙利算法O(n*m)果断华丽丽的TLE,请教了一下度娘,发现还有一种神算法—— Hopcroft-Karp,然后就get√新技能,一路小跑过了,有一点不明白的是hdu上竟然有人0ms过,这又是什么神姿势(吓哭!!!!!),额.........,扯远了.  H

hdu 2389 Rain on your Parade(二分图HK算法)

#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <cmath> using namespace std; const int inf=0x3f3f3f3f; const int maxn=3003; const int maxm=maxn*maxn; int xlink[maxn],ylink[maxn]; int dx[maxn

HDU2389 Rain on your Parade(HK模版)

题意: 在一个二维坐标系上有n个人和m把伞,每个人都有自己的移动速度, 问有多少人可以在s min内移动到不同的雨伞处(不允许两个人共用一把伞). 思路: 由于nm太大(3000),匈牙利会超时,就用HK算法 整理了HK的模版 /* *********************************************** //Author :devil //Created Time :2016/5/10 23:13:51 //********************************

HDU 2389 Rain on your Parade (二分图匹配(Hopcroft-Carp的算法模板))

Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Others) Total Submission(s): 3033    Accepted Submission(s): 952 Problem Description You're giving a party in the garden of your villa by the sea. The p

HDU2389(二分图匹配Hopcroft-Carp算法)

Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Others)Total Submission(s): 3310    Accepted Submission(s): 1066 Problem Description You’re giving a party in the garden of your villa by the sea. The p

HDU 2389 Rain on your Parade

http://acm.hdu.edu.cn/showproblem.php?pid=2389 题意:给暴风雨到来的时刻,m个人的坐标和单位速度,和n个救生衣的坐标.每个救生衣只能匹配一个人,求最多有多少人可以得到救生衣. 题解:典型二分图最大匹配题型.因为点比较多,使用Hopcroft-Karp算法.讲解:http://blog.csdn.net/wall_f/article/details/8248373 http://www.cnblogs.com/-sunshine/archive/201

HDU 2389 ——Rain on your Parade——————【Hopcroft-Karp求最大匹配、sqrt(n)*e复杂度】

Rain on your Parade Time Limit:3000MS     Memory Limit:165535KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2389 Description You’re giving a party in the garden of your villa by the sea. The party is a huge success, and everyone is h

hust 1164 4 Rain on your Parade

题目描述 You're giving a party in the garden of your villa by the sea. The party is a huge success, and everyone is here. It's a warm, sunny evening, and a soothing wind sends fresh, salty air from the sea. The evening is progressing just as you had imag

【wikioi】1922 骑士共存问题(网络流/二分图匹配)

用匈牙利tle啊喂?和网络流不都是n^3的吗.... (更新:what!!!!!!发现个无语的问题,.!!!!结构比数组快啊orz,这节奏不对啊....以后图都写结构的节奏啊... #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> using namespace