Rain on your Parade

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Others)
Total Submission(s): 3675    Accepted Submission(s): 1187

Problem Description
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.

 
Input
The 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 <= si
<= 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.
 
Output
For
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把伞,问最多能有多少匹配?
题解:HK算法减少时间.
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
const int N = ;
const int INF = ;
struct Node
{
int x,y,v;
} p[N],ub[N];
int graph[N][N];
int n,m,dist;
bool vis[N];
int cx[N],cy[N],dx[N],dy[N];
int dis(Node a,Node b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
bool searchpath()
{
queue<int> Q;
dist=INF;
memset(dx,-,sizeof(dx));
memset(dy,-,sizeof(dy));
for(int i=;i<=n;i++)
{
if(cx[i]==-)
{
Q.push(i);
dx[i]=;
}
}
while(!Q.empty())
{
int u=Q.front();
Q.pop();
if(dx[u]>dist) break;
for(int v=;v<=n;v++)
{
if(graph[u][v]&&dy[v]==-)
{
dy[v]=dx[u]+;
if(cy[v]==-) dist=dy[v];
else
{
dx[cy[v]]=dy[v]+;
Q.push(cy[v]);
}
}
}
}
return dist!=INF;
}
int findpath(int u)
{
for(int v=;v<=m;v++)
{
if(!vis[v]&&graph[u][v]&&dy[v]==dx[u]+)
{
vis[v]=;
if(cy[v]!=-&&dy[v]==dist)
{
continue;
}
if(cy[v]==-||findpath(cy[v]))
{
cy[v]=u;cx[u]=v;
return ;
}
}
}
return ;
}
void MaxMatch()
{
int res=;
memset(cx,-,sizeof(cx));
memset(cy,-,sizeof(cy));
while(searchpath())
{
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++)
{
if(cx[i]==-)
{
res+=findpath(i);
}
}
}
printf("%d\n\n",res);;
}
int main()
{
int tcase;
scanf("%d",&tcase);
int t = ;
while(tcase--)
{
memset(graph,,sizeof(graph));
int time;
scanf("%d",&time);
scanf("%d",&n);
for(int i=; i<=n; i++)
{
int v;
scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].v);
}
scanf("%d",&m);
for(int i=; i<=m; i++)
{
scanf("%d%d",&ub[i].x,&ub[i].y);
}
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
if(dis(p[i],ub[j])<=p[i].v*p[i].v*time*time)
{
graph[i][j] = ;
}
}
}
printf("Scenario #%d:\n",t++);
MaxMatch();
}
return ;
}

最新文章

  1. static 在多台下的特性
  2. Java中boolean型变量的默认值问题
  3. Hadoop上路-03_Hadoop JavaAPI
  4. 双slave的server_uuid同样问题
  5. swift3.0 扩展、协议(4)
  6. Down to the TLP: How PCI express devices talk (Part II)
  7. MapReduce的InputFormat学习过程
  8. html 页面视图中的资源文件(css/js/image)的路径问题。
  9. LeetCode 54. Spiral Matrix(螺旋矩阵)
  10. Java8 HashMap源码分析
  11. Network in Network
  12. 读书笔记-《Maven实战》-2018/4/16
  13. whereis、which、find的区别
  14. Access-Control-Allow-Origin跨域请求处理
  15. Mysql高级查询 内连接和外连接详解
  16. Nginx 配置 Jenkins 反向代理
  17. Lua脚本语法说明(转)
  18. eclipse 连接数据库记录
  19. MySQL安装及初步配置.md
  20. 【第四课】Linux的基础命令使用

热门文章

  1. (ex)BSGS题表
  2. Better Linux Disk Caching &amp; Performance with vm.dirty_ratio &amp; vm.dirty_background_ratio
  3. STL之六:map/multimap用法详解
  4. Moq/moq4
  5. [技巧篇]13.从今天开始做一个有理想的人,放弃alter的调试,拥抱console.log
  6. 51nod 1766 树上的最远点对——线段树
  7. PHP 练习3:租房子
  8. 关于cocos2d-x 中 CCEditBox 的输入位置和IOS虚拟键盘位置不重合的bug
  9. 教你 Shiro 整合 SpringBoot,避开各种坑(山东数漫江湖)
  10. hdu 1241Oil Deposits(BFS)