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 ...
随机推荐
- 【bzoj2698】染色 期望
题目描述 输入 输入一行四个整数,分别为N.M.S和T. 输出 输出一行为期望值,保留3位小数. 样例输入 5 1 2 3 样例输出 2.429 题解 期望 由于期望在任何时候都是可加的,因此只要算出 ...
- 【bzoj3105】[cqoi2013]新Nim游戏 高斯消元求线性基
题目描述 传统的Nim游戏是这样的:有一些火柴堆,每堆都有若干根火柴(不同堆的火柴数量可以不同).两个游戏者轮流操作,每次可以选一个火柴堆拿走若干根火柴.可以只拿一根,也可以拿走整堆火柴,但不能同时从 ...
- [CODEVS1912] 汽车加油行驶问题(分层图最短路)
传送门 吐槽:神tm网络流 dis[i][j][k] 表示到 (i, j) 还有 k 油的最优解 然后跑spfa,中间分一大堆情况讨论 1.当前队头还有油 1.目标点有加油站——直接过去 2.目标点每 ...
- Java2WSDL 和 WSDL2Java(Axis)
原文地址:https://www.ibm.com/developerworks/cn/webservices/ws-axisfaq/ 生成或取得WSDL文件 生成客户端或服务端代码 执行WSDL2Ja ...
- 【CTSC2010】产品销售(bzoj1920)
数据结构优化网络流…… 重新定义一下题目的各种条件: 第 $i$ 天能生产 $a_i$ 个物品: 第 $i$ 天有 $b_i$ 个物品的需求: 每存储一天物品(把订单提前一天)需要 $c_i$ 的花费 ...
- HDU1936 [贪心+KMP] 点的区间覆盖
每一行对话分别取匹配所有的表情 这样是一个n**2的匹配,可以用KMP 找出每行对话中的每个表情的左右端点 这样相当于就是问用最少多少个点 可以覆盖所有的区间(每个区间中放一个点表示覆盖) 贪心 按右 ...
- h5页面判断微信端用浏览器打开代码
<div class="weixin-tip"> <p> <img src="img/live_weixin.png" alt=& ...
- 13深入理解C指针之---内存管理
该系列文章源于<深入理解C指针>的阅读与理解,由于本人的见识和知识的欠缺可能有误,还望大家批评指教. 内存管理对所有程序都很重要,主要包括显式内存管理和隐式内存管理.其中隐式内存管理主要是 ...
- Linux 之 Redis
Linux 之 Redis 参考教程:[千峰教育] 一.Redis简介: 说明: 1.也是一种类似于Memcached的key-value机制的存储服务 2.是非关系型数据库(NoSQL)的一种 3. ...
- vue v-show与v-for同时配合v-bind使用并在href中传递多个参数的使用方法
最近在项目中,因为还没使用前端构建工具,还在使用vue+jquery方法渲染页面 碰到几个小问题,在此记录下作为vue学习之路上的一个小知识点 需求:1.数据列表存在与否状态,没有数据显示默认提示,有 ...