posts - 74,  comments - 33,  trackbacks - 0
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 were n 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 of v, now given the positions of the n persons and the m 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, then n lines, each has two integers 0 <= Xi, Yi <= 1000000 describing the position of the ith person, then m 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
本来以为是dp求解的,后来误以为KM做了一下,无果,后来想了想类似Max_Match搜索TLE
后来找到了这句话
-----------------------------------------------------------------------
n个人乘坐m个的(d¯e),已知人和的的坐标和人的速度,问每个人都打上
的的最短时间。假设的的位置不能变且没有两个人打同一个的。
假设T时间内大家都可以打上的,那么对于t > T的时间,大家也可以
打上的。因此,问题可以二分求解。
对于给定的T,如果人可以在该时间内走到某个的的位置,就在人和的
之间连一条边。于是问题的可行就要求该二分图的最大匹配数等于n。求
二分图最大匹配可以用Hungary算法。


----------------------------------------------------------------
来源:http://cuitianyi.com/ZOJ200901.pdf
就居然明白了原来类最小最优比例生成树,我二分的时候是利用最大时间上限t二分 每次原图中T<=t建图得到
边 1 ,否则无边。。结构很无情TLE,看了一下数据范围 1000000 0.00001 < v <= 10000000 郁闷。
随后改成把所有时间存储在Time数组中然后在数组中二分 不幸的是CE。Faint!!
原来是自己用了link做了数组标号,而C++优link函数。。。。。。A的很曲折。膜拜大牛的解题报告给了二分的思路
(今天我是想不到)
部分代码如下:
double dis(NODE a,NODE b){
    
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));    
}

bool DFS(int x){
    
for(int i=0;i<m;i++)
        
if(mark[x][i]&&!visited[i]){
            visited[i]
=true;
            
if(linkn[i]==-1||DFS(linkn[i])){
                linkn[i]
=x;
                
return true;    
            }
    
        }

    
return false;        
}

bool Max_Match(){
    
int i,sum=0;
    memset(linkn,
0xff,sizeof(linkn));
    
for(i=0;i<n;i++){
        memset(visited,
0,sizeof(visited));
        DFS(i);
    }

    
for(i=0;i<m;i++)
        
if(linkn[i]!=-1)sum++;
    
if(sum==n)return true;
    
else return false;    
}

void change(double x){
    
for(int i=0;i<n;i++)
        
for(int j=0;j<m;j++)
            
if(x>=map[i][j])mark[i][j]=true;
            
else mark[i][j]=false;    
}
posted on 2009-04-17 14:32 KNIGHT 阅读(148) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2009年4月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

常用链接

留言簿(8)

随笔档案

文章档案

Friends

OJ

搜索

  •  

最新评论

阅读排行榜

评论排行榜