hdu 2389 二分匹配
#include <iostream>
#include <vector>
using namespace std;
vector <vector <int> > V, guest;
vector <pair <int, int> > where;
vector <bool> hash;
vector <int> list1, list2;
int T, t, n, m, cnt = 1;
int pf(int a)
{
return a * a;
}
bool dfs(int a)
{
if (hash[a])
{
return false;
}
hash[a] = true;
int i;
for (i = 0; i < guest[a].size(); ++i)
{
int j = guest[a][i];
if (list2[j] == -1 || dfs(list2[j]))
{
list1[a] = j;
list2[j] = a;
return true;
}
}
return false;
}
void solve()
{
printf("Scenario #%d:\n", cnt++);
guest.clear();
guest.resize(n);
int i, j;
for (i = 0; i < n; ++i)
{
for (j = 0; j < m; ++j)
{
if (pf(V[i][0] - where[j].first) + pf(V[i][1] - where[j].second) <= pf(t * V[i][2]))
{
guest[i].push_back(j);
}
}
}
list1 = vector <int> (n, -1);
list2 = vector <int> (m, -1);
bool flag = true;
while (flag)
{
flag = false;
hash = vector <bool> (n, false);
for (i = 0; i < n; ++i)
{
if (list1[i] == -1 && dfs(i))
{
flag = true;
}
}
}
int num = 0;
for (i = 0; i < n; ++i)
{
if (list1[i] != -1)
{
num++;
}
}
printf("%d\n\n", num);
}
int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d %d", &t, &n);
V.clear();
V.resize(n);
int i;
for (i = 0; i < n; ++i)
{
V[i].resize(3);
cin >> V[i][0] >> V[i][1] >> V[i][2];
}
scanf("%d", &m);
where.clear();
where.resize(m);
for (i = 0; i < m; ++i)
{
cin >> where[i].first >> where[i].second;
}
solve();
}
return 0;
}
#include <vector>
using namespace std;
vector <vector <int> > V, guest;
vector <pair <int, int> > where;
vector <bool> hash;
vector <int> list1, list2;
int T, t, n, m, cnt = 1;
int pf(int a)
{
return a * a;
}
bool dfs(int a)
{
if (hash[a])
{
return false;
}
hash[a] = true;
int i;
for (i = 0; i < guest[a].size(); ++i)
{
int j = guest[a][i];
if (list2[j] == -1 || dfs(list2[j]))
{
list1[a] = j;
list2[j] = a;
return true;
}
}
return false;
}
void solve()
{
printf("Scenario #%d:\n", cnt++);
guest.clear();
guest.resize(n);
int i, j;
for (i = 0; i < n; ++i)
{
for (j = 0; j < m; ++j)
{
if (pf(V[i][0] - where[j].first) + pf(V[i][1] - where[j].second) <= pf(t * V[i][2]))
{
guest[i].push_back(j);
}
}
}
list1 = vector <int> (n, -1);
list2 = vector <int> (m, -1);
bool flag = true;
while (flag)
{
flag = false;
hash = vector <bool> (n, false);
for (i = 0; i < n; ++i)
{
if (list1[i] == -1 && dfs(i))
{
flag = true;
}
}
}
int num = 0;
for (i = 0; i < n; ++i)
{
if (list1[i] != -1)
{
num++;
}
}
printf("%d\n\n", num);
}
int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d %d", &t, &n);
V.clear();
V.resize(n);
int i;
for (i = 0; i < n; ++i)
{
V[i].resize(3);
cin >> V[i][0] >> V[i][1] >> V[i][2];
}
scanf("%d", &m);
where.clear();
where.resize(m);
for (i = 0; i < m; ++i)
{
cin >> where[i].first >> where[i].second;
}
solve();
}
return 0;
}