题目链接: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 (二分匹配+二分查找)的更多相关文章

  1. ZOJ 3156 Taxi (二分 + 二分匹配)

    题意:给定 n 个人坐标, m 辆车的坐标,还有人的速度,要求每个人要进一辆不同的车,问你所有都进车的最短时间是多少. 析:首先二分时间 mid,很明显就是最后那个人进车的时间,然后如果把第 i 个人 ...

  2. fafu 1568 Matrix(二分匹配+二分)

    Description:   You are given a matrix which <= n <= m <= ). You are supposed to choose n el ...

  3. POJ 2289 多重二分匹配+二分 模板

    题意:在通讯录中有N个人,每个人能可能属于多个group,现要将这些人分组m组,设各组中的最大人数为max,求出该最小的最大值 下面用的是朴素的查找,核心代码find_path复杂度是VE的,不过据说 ...

  4. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  5. ZOJ 1654 二分匹配基础题

    题意: 给你一副图, 有草地(*),空地(o)和墙(#),空地上可以放机器人, 机器人向上下左右4个方向开枪(枪不能穿墙),问你在所有机器人都不相互攻击的情况下能放的最多的机器人数. 思路:这是一类经 ...

  6. zoj 1002 Fire Net (二分匹配)

    Fire Net Time Limit: 2 Seconds      Memory Limit: 65536 KB Suppose that we have a square city with s ...

  7. zoj 2362 Beloved Sons【二分匹配】

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2361 来源:http://acm.hust.edu.cn/vjudg ...

  8. HDU 2063 过山车(二分匹配入门)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...

  9. POJ 2289(多重匹配+二分)

    POJ 2289(多重匹配+二分) 把n个人,分到m个组中.题目给出每一个人可以被分到的那些组.要求分配完毕后,最大的那一个组的人数最小. 用二分查找来枚举. #include<iostream ...

随机推荐

  1. OpenCV For Java环境搭建与功能演示

    http://blog.csdn.net/jia20003/article/details/68944486

  2. samba安装和配置

    windows和windows系统之间要实现文件共享是通过网络邻居实现linux和windows之间通过什么来实现文件共享呢?一.通过文件挂载(首先要制作ISO镜像文件,然后在用挂载命令)二.通过sa ...

  3. 关于element-ui select组件change事件只要数据变化就会触发的解决办法

    使用select组件和表格组件结合起来用,但是发现在点击下一页的时候,由于select当中的数据发生了变化,所以也会触发select当中的change事件,但是我只希望在我主动改变select组件当中 ...

  4. docker的通俗理解

    自己买了个服务器,前不久搭建好的一个网站,想要再搞一个站点,无奈只能修改端口后,再部署另外一个站点.繁琐的配置运行环境,迁移网站,是否让你感觉到很繁琐?服务器不想用了,想搬迁到另外一台服务器去部署,先 ...

  5. UVa1476 Error Curves

    画出函数图像后,发现是一个类似V字型的图. 可以用三分法找图像最低点 WA了一串,之后发现是读入优化迷之被卡. /*by SilverN*/ #include<iostream> #inc ...

  6. Codeforces Gym101502 K.Malek and Summer Semester

    K. Malek and Summer Semester   time limit per test 1.0 s memory limit per test 256 MB input standard ...

  7. 2012 ACM/ICPC 亚洲区 金华站

    题目链接  2012金华区域赛 Problem A 按a/b从小到大的顺序排队进行体检即可 #include<iostream> #include<cstdio> #inclu ...

  8. Java开发者使用C++写程序踩的坑

    笔者是一个很矛盾的人.平时用Java.但是一开始学习的时候学的是汇编语言,而且对C语言也很熟悉.为什么不学C++呢?是因为我可以完全用Java的编码规范去写C++.因此我不需要了解更多的诸如C++的命 ...

  9. 高并发场景下System.currentTimeMillis()的性能优化

    一.前言 System.currentTimeMillis()的调用比new一个普通对象要耗时的多(具体耗时高出多少我也不知道,不过听说在100倍左右),然而该方法又是一个常用方法, 有时不得不使用, ...

  10. Java创建和解析Json数据方法(四)——json-lib包的使用

    (四)json-lib包的使用         既然json-lib包比org.json包重量级,那么json-lib包肯定有很多org.json包没有的类和方法,这篇笔记简单记录json-lib包中 ...