ZOJ 3156 Taxi (二分匹配+二分查找)
题目链接:Taxi
Taxi
Time Limit: 1 Second
Memory Limit: 32768 KB
As we all know, it often rains suddenly in Hangzhou during summer time.I suffered a heavy rain when I was walking on the street yesterday, so I decided to take a taxi back school. I found that there weren people on the street trying to take taxis,
and m taxicabs on the street then. Supposing that the cars waited still and each person walked at a speed ofv, now given the positions of then persons and them taxicabs, you should find the minimum time needed for all the
persons to get on the taxicabs. Assume that no two people got on the same taxicab.
Input
For each case, you are given two integers 0 <= n <= 100 and n< =m <= 100 on the first line, thenn lines, each has two integers 0 <=Xi,Yi <= 1000000 describing the position of the ith person, thenm
lines, each has two integers 0 <=xi,yi< = 1000000 describing the position the ith taxicab, then a line has a float 0.00001 <v <= 10000000 which is the speed of the people.
Output
You shuold figue out one float rounded to two decimal digits for each case.
Sample Input
2 3
0 0
0 1
1 0
1 1
2 1
1
Sample Output
1.00
题意:n个人,m辆车,不论什么是n个人的坐标。和m个车的坐标,计算全部人上车所用的最少时间
错了5遍,dis数组开小了。。。
思路:和POJ2536几乎相同。仅仅是本题是求最小时间,所以在二分查找最小时间的同一时候,进行推断当前点是否存在增广路
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
#define init(a) memset(a,0,sizeof(a))
#define PI acos(-1,0)
using namespace std;
const int maxn = 110;
const int maxm = 10010;
#define lson left, m, id<<1
#define rson m+1, right, id<<1|1
#define min(a,b) (a>b)?b:a
#define max(a,b) (a>b)?a:b int n,m;
bool vis[maxn];
int line[maxn];
double ma[maxn][maxn];
struct node
{
double x,y;
};
node g[maxn],h[maxn];
double dis[maxm],st; int cmp(const void *a,const void *b)
{
return (*(double *)a > *(double *)b) ? 1 : -1;
} int DFS(int u)
{
for(int v = 1; v <= m; v++)
{
if (ma[u][v]<=st && !vis[v])
{
vis[v] = 1;
if (line[v]== -1 || DFS(line[v]))
{
line[v] = u;
return 1;
}
}
}
return 0;
}
int K_M()
{
memset(line,-1,sizeof line);
for (int i=1; i<=n; i++)
{
init(vis);
if (DFS(i)==0)
return 0;
}
return 1;
}
int ans;
void B_search(int num)
{
int low = 0;
int high = num - 1; while (low <= high)
{
//printf("low = %d high = %d\n",low,high);
//printf("mid = %d",mid);
int mid = (low + high)/2;
st = dis[mid];
//printf("st = %.2lf\n",st);
//printf("ans = %lf\n",ans);
if ( K_M()==1 )
{
ans = mid;
high = mid - 1;
}
else
low = mid + 1;
}
}
int main()
{
double v;
int num = 0;
while(scanf("%d%d",&n,&m)!=EOF)
{
init(ma);
num = 0;
for (int i=1; i<=n; i++)
scanf("%lf%lf",&g[i].x,&g[i].y);
/*for(int i = 1;i<=n;i++)
printf("g.x = %lf g.y = %lf\n",g[i].x,g[i].y);*/ for (int i=1; i<=m; i++)
scanf("%lf%lf",&h[i].x,&h[i].y); /*for(int i = 1;i<=n;i++)
printf("h.x = %lf h.y = %lf\n",h[i].x,h[i].y);*/ scanf("%lf",&v); for (int i=1; i<=n; i++)
{
for (int j=1; j<=m; j++)
{
ma[i][j] = (sqrt((g[i].x-h[j].x)*(g[i].x-h[j].x)+(g[i].y-h[j].y)*(g[i].y-h[j].y))/v);
dis[num++] = ma[i][j]; }
}
qsort(dis,num,sizeof(dis[0]),cmp);
/*for(int i = 0;i<num;i++)
printf("%.2lf ",dis[i]);
printf("\n");*/
B_search(num);
printf("%.2lf\n",dis[ans]);
}
return 0;
}
ZOJ 3156 Taxi (二分匹配+二分查找)的更多相关文章
- ZOJ 3156 Taxi (二分 + 二分匹配)
题意:给定 n 个人坐标, m 辆车的坐标,还有人的速度,要求每个人要进一辆不同的车,问你所有都进车的最短时间是多少. 析:首先二分时间 mid,很明显就是最后那个人进车的时间,然后如果把第 i 个人 ...
- fafu 1568 Matrix(二分匹配+二分)
Description: You are given a matrix which <= n <= m <= ). You are supposed to choose n el ...
- POJ 2289 多重二分匹配+二分 模板
题意:在通讯录中有N个人,每个人能可能属于多个group,现要将这些人分组m组,设各组中的最大人数为max,求出该最小的最大值 下面用的是朴素的查找,核心代码find_path复杂度是VE的,不过据说 ...
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
- ZOJ 1654 二分匹配基础题
题意: 给你一副图, 有草地(*),空地(o)和墙(#),空地上可以放机器人, 机器人向上下左右4个方向开枪(枪不能穿墙),问你在所有机器人都不相互攻击的情况下能放的最多的机器人数. 思路:这是一类经 ...
- zoj 1002 Fire Net (二分匹配)
Fire Net Time Limit: 2 Seconds Memory Limit: 65536 KB Suppose that we have a square city with s ...
- zoj 2362 Beloved Sons【二分匹配】
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2361 来源:http://acm.hust.edu.cn/vjudg ...
- HDU 2063 过山车(二分匹配入门)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...
- POJ 2289(多重匹配+二分)
POJ 2289(多重匹配+二分) 把n个人,分到m个组中.题目给出每一个人可以被分到的那些组.要求分配完毕后,最大的那一个组的人数最小. 用二分查找来枚举. #include<iostream ...
随机推荐
- Etcd和ZooKeeper,究竟谁在watch的功能表现更好?
ZooKeeper和Etcd的主要异同可以参考这篇文章,此外,Etcd的官网上也有对比表格(https://coreos.com/etcd/docs/latest/learning/why.html) ...
- 【Luogu】P2053修车(费用流)
题目链接 早上状态不好,虚树搞崩只好来刷网络流了qwq. (然后我犹豫几秒之后看了题解) 使用拆点大法把工人拆成n*m个点,然后每个点代表每个时间段的工人, 然后从车到每个工人点连一条边,权值是耽误的 ...
- bootstrap 事件shown.bs.modal用于监听并执行你自己的代码【写hostmanger关联部门遇到的问题及解决方法】
背景:记录写hostmanger中用户下拉框关联部门遇到的问题及解决方法 问题:需求是展示页面展示用户所属的部门,点击修改按钮后,弹出对应的model,这个时候部门的select要默认选中用户所在的s ...
- 开源编辑器ueditor
http://ueditor.baidu.com/website/onlinedemo.html
- Java-堆排序
public class Main { public static void main(String[] args) { int a[] = {8, 2, 5, 6, 4, 8, 9, 7, 14, ...
- css3 实现居中的9中方法
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- #define xxx do{...} while(0) 宏定义
linux内核和其他一些开源的代码中,经常会遇到这样的代码: do{ ... }while(0) 这样的代码一看就不是一个循环,do..while表面上在这里一点意义都没有,那么为什么要这么用呢? 实 ...
- VS debug调试方法
F5 开始调试,执行到断点 Shift + F5 停止调试 F9 在光标所在行添加断点 Shift + F9 QuickWatch Shift Ctrl F9 delete all 断点 F10 单步 ...
- osstatus -9801 workerman websocket 小程序不带端口
帮事业部的同事,解决问题,坑总结 小程序出现,osstatus -9801 情况好多,说一下配置环境可解决的方法和问题 tls 1.2, php 5.6+, nginx, workerman 做的 w ...
- Python基础数据类型补充及深浅拷贝
本节主要内容:1. 基础数据类型补充2. set集合3. 深浅拷贝主要内容:一. 基础数据类型补充首先关于int和str在之前的学习中已经讲了80%以上了. 所以剩下的自己看一看就可以了.我们补充给一 ...