链接:

https://vjudge.net/problem/HDU-2389

题意:

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 imagined. It could be the perfect end of a beautiful day.

But nothing ever is perfect. One of your guests works in weather forecasting. He suddenly yells, “I know that breeze! It means its going to rain heavily in just a few minutes!” Your guests all wear their best dresses and really would not like to get wet, hence they stand terrified when hearing the bad news.

You have prepared a few umbrellas which can protect a few of your guests. The umbrellas are small, and since your guests are all slightly snobbish, no guest will share an umbrella with other guests. The umbrellas are spread across your (gigantic) garden, just like your guests. To complicate matters even more, some of your guests can’t run as fast as the others.

Can you help your guests so that as many as possible find an umbrella before it starts to pour?

Given the positions and speeds of all your guests, the positions of the umbrellas, and the time until it starts to rain, find out how many of your guests can at most reach an umbrella. Two guests do not want to share an umbrella, however.

思路:

二分图最大匹配,匈牙利算法超时。改用hopcroft-karp算法。

吧能在时间内跑到的伞加到人的配对上,hopcroft-karp算法还不是太懂。

代码:

#include <iostream>
#include <cstdio>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
const int MAXN = 3e3+10;
const int INF = 1<<30; struct Node
{
double x, y;
};
Node P[MAXN], U[MAXN];
vector<int> G[MAXN];
double Speed[MAXN];
int Link_l[MAXN], Vis[MAXN];
int Link_r[MAXN];
int Dis_x[MAXN], Dis_y[MAXN];
int n, m;
int dis; double GetLen(Node a, Node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} bool Search()
{
memset(Dis_x, -1, sizeof(Dis_x));
memset(Dis_y, -1, sizeof(Dis_y));
dis = INF;
queue<int> que;
for (int i = 1;i <= m;i++)
{
if (Link_r[i] == -1)
que.emplace(i);
Dis_x[i] = 0;
}
while (!que.empty())
{
int u = que.front();
que.pop();
if (Dis_x[u] > dis)
break;
for (int i = 0;i < G[u].size();i++)
{
int node = G[u][i];
if (Dis_y[node] == -1)
{
Dis_y[node] = Dis_x[u]+1;
if (Link_l[node] == -1)
dis = Dis_y[node];
else
{
Dis_x[Link_l[node]] = Dis_y[node]+1;
que.push(Link_l[node]);
}
}
}
}
return dis != INF;
} bool Dfs(int x)
{
for (int i = 0;i < G[x].size();i++)
{
int node = G[x][i];
if (Vis[node] || Dis_y[node] != Dis_x[x]+1)
continue;
Vis[node] = 1;
if (Link_l[node] != -1 && Dis_y[node] == dis)
continue;
if (Link_l[node] == -1 || Dfs(Link_l[node]))
{
Link_l[node] = x;
Link_r[x] = node;
return true;
}
}
return false;
} int Solve()
{
memset(Link_l, -1, sizeof(Link_l));
memset(Link_r, -1, sizeof(Link_r));
int cnt = 0;
while (Search())
{
memset(Vis, 0, sizeof(Vis));
for (int i = 1;i <= m;i++)
{
if (Link_r[i] == -1 && Dfs(i))
cnt++;
}
}
return cnt;
} int main()
{
int t, cnt = 0;
scanf("%d", &t);
while (t--)
{
int time;
scanf("%d", &time);
scanf("%d", &m);
for (int i = 1;i <= m;i++)
G[i].clear();
for (int i = 1;i <= m;i++)
scanf("%lf%lf%lf", &P[i].x, &P[i].y, &Speed[i]);
scanf("%d", &n);
for (int i = 1;i <= n;i++)
scanf("%lf%lf", &U[i].x, &U[i].y);
for (int i = 1;i <= m;i++)
{
for (int j = 1;j <= n;j++)
{
double len = GetLen(P[i], U[j]);
if (len/Speed[i] <= time)
G[i].push_back(j);
}
}
int sum = Solve();
printf("Scenario #%d:\n%d\n\n", ++cnt, sum);
} return 0;
}

最新文章

  1. 一个windows下的ddos样本
  2. Ionic 常见问题及解决方案
  3. 【转帖】ECLIPSE-JEE-LUNA-SR2官方汉化教程
  4. oracle 表迁移方法 (一)
  5. 实现当UILable的内容超出其范围后自动滚动效果
  6. JAVA8,SPRING,ANGULARJS对项目
  7. python web框架之Tornado
  8. GIT-windows系统部署gitblit服务器
  9. Redux,基础
  10. day14- 面向对象基础(一)
  11. excel导出导入通用方法
  12. ---Ubuntu 16.04 server 不能关机问题解决
  13. 329 experience
  14. 转 Java虚拟机5:Java垃圾回收(GC)机制详解
  15. MyBatis学习之多表查询
  16. WebGl 多缓冲区传递颜色和坐标(矩形)
  17. 在Google Chrome中快速解除网页屏蔽鼠标右键、复制等限制
  18. latex排版(CTeX winEdit输出“系统找不到指定的文件”的终极解决办法)
  19. 软考之信息安全工程师(包含2016-2018历年真题详解+官方指定教程+VIP视频教程)
  20. C# 字符,字符串和文本处理。

热门文章

  1. LeetCode.917-只反转字母(Reverse Only Letters)
  2. 意想不到的JavaScript(每日一题3)
  3. BUUOJ reverse 刮开有奖
  4. hive_server2的权限控制
  5. Maven - Maven3实战学习笔记(1)Maven使用入门
  6. 洛谷 P2023 维护序列 题解
  7. redis 小结 一
  8. laravel的monolog使用
  9. 实例学习——爬取Pexels高清图片
  10. synchronized锁住的是代码还是对象,以及synchronized底层实现原理