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 ...
随机推荐
- 第一次使用HTML
1.第一次使用HTML <title>第一次使用HTML</title></head><body>hello,HTML2.文本处理 <title& ...
- Unity Microphone 录音时 检测声音大小
刚开始以为只取录音时的最后一个sample来判断音量大小,发现都检测不到. 后来搜索了一下,原来需要取一段sample来判断,有的是这一段取平均值作为音量大小.我这里是取出一段sample中的峰值(p ...
- 解决c#所有单线程单元(STA)线程都应使用泵式等待基元(如 CoWaitForMultipleHandles),并在运行时间很长的操作过程中定期发送消息。 转载
最近做一个后来程序,启动了事务后有一段操作业务,当运行一段时间后,出现这个异常 CLR 无法从 COM 上下文 0x1b1c38 转换为 COM 上下文 0x1b1da8,这种状态已持续 60 秒.拥 ...
- poj 6243 Dogs and Cages
Dogs and Cages Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- Python入门--19--else语句、with语句
1.else与while连用: x=input('请输出一个整数:') while x>0 x=x-2 print(x) else: print('x已经小于等于零了!') 2.else与try ...
- Scrapy学习-20-数据收集
Scrapy的数据收集功能 定义 Scrapy提供了方便的收集数据的机制.数据以key/value方式存储,值大多是计数值. 该机制叫做数据收集器(Stats Collector),可以通过 Craw ...
- HDU 1754:I Hate It(线段树-单点更新)
题意: 1~N这些人有一些分数,之后有M条操作.要求支持两种操作:更新其中某个人的成绩,查询[A,B]区间内的人的最高成绩. ( 0<N<=200000,0<M<5000 ) ...
- [Inside HotSpot] UseParallelGC和UseParallelOldGC的区别
JVM的很多参数命名很有迷惑性,-XX:+UseParallel,-XX:+UseParallelOldGC,-XX:+UseParNewGC,-XX:+UseConcMarkSweepGC咋一看容易 ...
- deferred 对象
转载,原文连接:http://www.ruanyifeng.com/blog/2011/08/a_detailed_explanation_of_jquery_deferred_object.html ...
- Ubuntu 16.04下使用Wine安装正则表达式工具RegexBuddy 4
说明: 1.使用的Wine版本是深度出品(Deepin),已经精简了很多没用的配置,使启动能非常快,占用资源小. 2.关于没有.wine文件夹的解决方法:在命令行上运行winecfg: 下载: (链接 ...