ZOJ 3156 Taxi (二分 + 二分匹配)
题意:给定 n 个人坐标, m 辆车的坐标,还有人的速度,要求每个人要进一辆不同的车,问你所有都进车的最短时间是多少。
析:首先二分时间 mid,很明显就是最后那个人进车的时间,然后如果把第 i 个人到时第 j 辆车的时间小于 mid,那么就从 i 向 j + n 连一条边,然后进行十分匹配,如果是完全匹配,匹配数等于 n,那么就是可以的,否则就是不可以。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define be begin()
#define ed end()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
//#define all 1,n,1
#define FOR(i,n,x) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.in", "r", stdin)
#define freopenw freopen("out.out", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int maxn = 100 + 10;
const int maxm = 1e6 + 10;
const LL mod = 1000000007;
const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
}
inline int readInt(){ int x; scanf("%d", &x); return x; } int x[maxn], y[maxn];
int a[maxn], b[maxn];
double v;
LL d[maxn][maxn]; LL dist(int i, int j){
return sqr((LL)(a[i]-x[j])) + sqr((LL)(b[i]-y[j]));
} int match[maxn<<1];
bool vis[maxn<<1];
vector<int> G[maxn<<1]; void addEdge(int u, int v){
G[u].pb(v); G[v].pb(u);
} void init(){
FOR(i, n+m+5, 0) G[i].cl;
} bool dfs(int u){
vis[u] = 1;
for(int i = 0; i < G[u].sz; ++i){
int v = G[u][i];
int w = match[v];
if(w < 0 || !vis[w] && dfs(w)){
match[u] = v;
match[v] = u;
return true;
}
}
return false;
} bool judge(double mid){
int ans = 0;
init();
FOR(i, n, 0) FOR(j, m, 0)
if((double)d[i][j] <= sqr(mid * v))
addEdge(i, j + n);
ms(match, -1);
for(int i = 0; i < n; ++i) if(match[i] < 0){
ms(vis, 0); if(dfs(i)) ++ans;
}
return ans == n;
} int main(){
while(scanf("%d %d", &n, &m) == 2){
for(int i = 0; i < n; ++i) scanf("%d %d", a + i, b + i);
for(int i = 0; i < m; ++i){
scanf("%d %d", x + i, y + i);
for(int j = 0; j < n; ++j)
d[j][i] = dist(j, i);
}
scanf("%lf", &v);
double l = 0., r = 1e7 / v;
while(r-l > eps){
double mid = (l + r) / 2.;
if(judge(mid)) r = mid;
else l = mid;
}
printf("%.2f\n", l);
}
return 0;
}
ZOJ 3156 Taxi (二分 + 二分匹配)的更多相关文章
- ZOJ 3156 Taxi (二分匹配+二分查找)
题目链接:Taxi Taxi Time Limit: 1 Second Memory Limit: 32768 KB As we all know, it often rains sudde ...
- UVALive 2238 Fixed Partition Memory Management(二分完美匹配)
题意:计算机中有一些固定大小的内存,内存越大,处理速度越快.对于一个程序,加入不同的内存空间,处理所需时间不同.现给出m个内存空间,n个程序,对于每个程序程序,有k组数据(s,t),分别表示当程序 i ...
- hdu2413(二分+二分匹配)
题意:人和外星人星球大战,人总共有H个星球,外星人有A个星球,现在人要用飞船去打外星人的飞船,要求每个人类星球只能对战一个外星球,且每个星球都开始有己知的飞船数,不论是人或外星人的星球,并每个星球都有 ...
- BZOJ_4443_[Scoi2015]小凸玩矩阵_二分+二分图匹配
BZOJ_4443_[Scoi2015]小凸玩矩阵_二分+二分图匹配 Description 小凸和小方是好朋友,小方给小凸一个N*M(N<=M)的矩阵A,要求小秃从其中选出N个数,其中任意两个 ...
- Hihocoder 1128 二分·二分查找
二分·二分查找 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Nettle最近在玩<艦これ>,因此Nettle收集了很多很多的船(这里我们假设Nettle氪 ...
- hihoCoder 1133 二分·二分查找之k小数(TOP K算法)
#1133 : 二分·二分查找之k小数 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在上一回里我们知道Nettle在玩<艦これ>,Nettle的镇守府有很 ...
- hihocoder hiho第38周: 二分·二分答案 (二分搜索算法应用:二分搜索值+bfs判断可行性 )
题目1 : 二分·二分答案 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在上一回和上上回里我们知道Nettle在玩<艦これ>,Nettle在整理好舰队之后 ...
- hiho week 38 P1 : 二分·二分答案
P1 : 二分·二分答案 Time Limit:10000ms Case Time Limit:1000ms Memory Limit:256MB 描述 在上一回和上上回里我们知道Nettle在玩&l ...
- hiho week 37 P1 : 二分·二分查找之k小数
P1 : 二分·二分查找之k小数 Time Limit:10000ms Case Time Limit:1000ms Memory Limit:256MB 描述 在上一回里我们知道Nettle在玩&l ...
随机推荐
- 使用Nginx做转发和匹配替换
Nginx是一个强大的服务器软件,由于处理数据内容处于第七层协议应用层的原因,所以获取的数据也比较完整: Nginx做转发: 这个很简单,vi nginx.conf(编辑nginx配置文件) 添加lo ...
- 如何指定vim 的查找是从上往下还是从下往上[z]
vim 搜索可以是 / 或者 ?,前者是往下找,后者是往前找. 用 n 查找下一个的时候,就和这两个指令指定的方向相同.如果你想改变方向的话,比如想往下找,那么 / 完了直接回车就行了.表示再次使用上 ...
- [z]Libevent使用例子,从简单到复杂
[z]http://blog.csdn.net/luotuo44/article/details/39670221 本文从简单到复杂,展示如何使用libevent.网上的许多例子都是只有服务器端的,本 ...
- Linux定时任务Crontab使用 提示no crontab for root
使用命令查询crontab 任务时,一直提示:no crontab for root .查看了一些资料,说是crontab在初始时,设置了一次编辑方式,所以试了一下crontab -e的方式编辑,即在 ...
- 5J - 复习时间
为了能过个好年,xhd开始复习了,于是每天晚上背着书往教室跑.xhd复习有个习惯,在复习完一门课后,他总是挑一门更简单的课进行复习,而他复习这门课的效率为两门课的难度差的平方,而复习第一门课的效率为1 ...
- 使用GrabCut提取前景图像的示范代码
#include<opencv2/opencv.hpp> bool selectObject = false; cv::Point origin; cv::Rect selection; ...
- andorid 手机外部储存
.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...
- (O)js核心:作用域链
作用域 在一个函数被调用的时候,函数的作用域才会存在.此时,在函数还没有开始执行的时候,开始创建函数的作用域: 函数作用域的创建步骤: 1.函数形参的声明. 2.函数变量的声明. 3.普通变量的声 ...
- 12. pt-index-usage
pt-index-usage h=192.168.100.101,P=3306,u=admin,p=admin /data/mysql3306/data/slow.log 根据slow log来判断i ...
- rap2与postman自动化测试
rap2的接口数据可以全部导入postman: 在collections集合里面点击run;