题目链接: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;
}

最新文章

  1. 在iOS中实现类似安卓自动消失提示框
  2. 【BZOJ-1176&amp;2683】Mokia&amp;简单题 CDQ分治
  3. javax.swing.JList 设置分割线
  4. php文件删除unlink()详解
  5. http://www.aboutyun.com/thread-6551-1-1.html
  6. Android 国际化图片资源文件
  7. HDU 4628 Pieces(DP + 状态压缩)
  8. iOS 任意类型数据转换字符串
  9. Windows上的的神技
  10. 2.1 工具使用:xmind
  11. Sublime安装Package Control插件
  12. 【Unity与23种设计模式】状态模式(State)
  13. 用.net中的SqlBulkCopy类批量复制数据 (转载)
  14. Angular 向组件传递模板的几种方法
  15. WordPress文章中插入qq表情
  16. python logging模块使用流程
  17. 使用VB6读取数据库资源并发送邮件(原创)
  18. monitor.sh
  19. DOM对象,控制HTML元素
  20. html5 p1练习1,移动页面,标准标签布局

热门文章

  1. 【Luogu】P1169棋盘制作(单调栈)
  2. IE7下z-index失效问题
  3. BZOJ4816 [Sdoi2017]数字表格 【莫比乌斯反演】
  4. Unity Microphone 录音时 检测声音大小
  5. 实验六 TLS协议报文解析
  6. 前端开发 CSS中你所不知道的伪类与伪元素的区别--摘抄
  7. 标准C程序设计七---113
  8. udp 多播
  9. npm 查看模块全部版本
  10. 本地安装Sass,Compass