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.

InputThe input starts with a line containing a single integer, the number of test cases. 
Each test case starts with a line containing the time t in minutes until it will start to rain (1 <=t <= 5). The next line contains the number of guests m (1 <= m <= 3000), followed by m lines containing x- and y-coordinates as well as the speed si in units per minute (1 <= s i <= 3000) of the guest as integers, separated by spaces. After the guests, a single line contains n (1 <= n <= 3000), the number of umbrellas, followed by n lines containing the integer coordinates of each umbrella, separated by a space. 
The absolute value of all coordinates is less than 10000. 
OutputFor each test case, write a line containing “Scenario #i:”, where i is the number of the test case starting at 1. Then, write a single line that contains the number of guests that can at most reach an umbrella before it starts to rain. Terminate every test case with a blank line. 
Sample Input

2
1
2
1 0 3
3 0 3
2
4 0
6 0
1
2
1 1 2
3 3 2
2
2 2
4 4

Sample Output

Scenario #1:
2 Scenario #2:
2
题意:给n个人坐标速度和m个伞坐标进行匹配,转化成二分图匹配
题解:二遍循环判断是否能到达,进行匹配,匈牙利算法会tle,用Hopcroft Karp算法(暂时还不是很理解,先背下来)
参考的博客,图很清楚但是注释有点少http://www.cnblogs.com/penseur/archive/2013/06/16/3138981.html
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const int N=+,maxn=+,inf=0x3f3f3f3f; struct edge{
int x,y,v;
}g[N],u[N]; int n,m,dis;
bool used[N],ok[N][N];
int mx[N],my[N];//mx保存右侧匹配点,my保存左侧匹配点
int dx[N],dy[N]; double road(edge a,edge b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool searchP()//寻找增广路径集
{
queue<int>q;
dis=inf;
memset(dy,-,sizeof dy);
memset(dx,-,sizeof dx);
for(int i=;i<=n;i++)
if(mx[i]==-)//将未访问过的左侧点加入队列
{
q.push(i);
dx[i]=;//距离设为0
}
while(!q.empty()){
int u=q.front();
q.pop();
if(dx[u]>dis)break;
for(int i=;i<=m;i++)//取左侧点匹配到右侧
{
if(ok[u][i]&&dy[i]==-)//右侧点联通且未访问
{
dy[i]=dx[u]+;//i对应距离为u对应距离+1
if(my[i]==-)dis=dy[i];//i无匹配点
else
{
dx[my[i]]=dy[i]+;
q.push(my[i]);
}
}
}
}
return dis!=inf;
}
bool dfs(int x)
{
for(int i=;i<=m;i++)
{
if(!used[i]&&ok[x][i]&&dy[i]==dx[x]+)//没有访问过且距上一点为1
{
used[i]=;
if(my[i]!=-&&dy[i]==dis)continue;
if(my[i]==-||dfs(my[i]))
{
my[i]=x;
mx[x]=i;
return ;
}
}
}
return ;
}
int solve()
{
int ans=;
memset(mx,-,sizeof mx);
memset(my,-,sizeof my);
while(searchP()){
memset(used,,sizeof used);
for(int i=;i<=n;i++)
if(mx[i]==-&&dfs(i))
ans++;
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int t,time;
cin>>t;
for(int k=;k<=t;k++)
{
cin>>time>>n;
for(int i=;i<=n;i++)cin>>g[i].x>>g[i].y>>g[i].v;
cin>>m;
for(int i=;i<=m;i++)cin>>u[i].x>>u[i].y;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(time*g[i].v>=road(g[i],u[j]))ok[i][j]=;
else ok[i][j]=;
}
}
cout<<"Scenario #"<<k<<":"<<endl<<solve()<<endl<<endl;
}
return ;
}

最新文章

  1. ios学习资源
  2. 使用memadmin可视化监视我们的memcache
  3. http请求相关
  4. nodejs模块——http模块
  5. 实战:ASP.NET MVC中把Views下面的视图放到Views文件夹外
  6. PostgreSQL Monitor pg_view
  7. (转)《深入理解java虚拟机》学习笔记7——Java虚拟机类生命周期
  8. 信号量 sem_t 进程同步
  9. bzoj 2075: [POI2004]KAG
  10. STL之使用vector排序
  11. kill命令&quot;-1&quot;这个参数到底是杀进程还是reload?(转)
  12. Citrix 服务器虚拟化之三 Xenserver 网络管理
  13. 有关sqlitedrop数据库重建比delete方式来清空数据库更加有效率
  14. Python爬虫初学(二)—— 爬百度贴吧
  15. pentaho专题之reporting design入门指南
  16. leetcode python 033 旋转数组查找
  17. 原生Ajax GET+POST请求无刷新实现文本框用户名是否被注册
  18. python的执行顺序
  19. Javascript高级调试——console.table()
  20. set集合遍历

热门文章

  1. Asp.NetCore1.1版本没了project.json,这样来生成跨平台包
  2. GitHub中最强大的iOS Notifications和AlertView框架,没有之一!
  3. MyBatis 源码分析——映射结果
  4. unity3d屏蔽Windows10输入法
  5. iOS 历史浏览网页的定向跳转
  6. 老李分享: 并行计算基础&amp;编程模型与工具 1
  7. span表情输入框 --- Author: rose &amp;&amp; lvyerose@163.com
  8. poj 2155 Matrix (二维树状数组)
  9. JavaScript基础学习(八)&mdash;事件
  10. AngularJS进入使用前的准备工作