Zoj 3156 taxi bipartite graph + Binary Search

Source: Internet
Author: User

People and taxis are on the street. Enter people and car locations and calculate the shortest time for everyone to get on the bus.

Practice: HungaryAlgorithmDirectly...

# Include <cstdio> # include <cstring> # include <cmath> # include <algorithm> using namespace STD; const int LMT = 102; double gra [LMT] [LMT], chose [LMT * LMT], X [LMT <1], Y [LMT <1], have; int xnum, ynum, CNT, link [LMT]; bool vis [LMT]; bool DFS (int I) {for (Int J = 0; j <ynum; j ++) {If (GRA [I] [J] <= have &&! Vis [J]) {vis [J] = true; If (link [J] =-1 | DFS (link [J]) {link [J] = I; return true ;}} return false;} bool Hu (void) {memset (link,-1, sizeof (Link )); for (INT I = 0; I <xnum; I ++) {memset (VIS, 0, sizeof (VIS); If (! DFS (I) return 0;} return 1;} double solve (void) {int L = 0, r = cnt-1, M; double res = 0; while (L <= r) {int M = (L + r)> 1; Have = chose [m]; If (Hu () {res = have; R = m-1;} else l = m + 1;} return res;} int main () {Double V; int I; while (~ Scanf ("% d", & xnum, & ynum) {int I; CNT = 0; memset (GRA,-1, sizeof (GRA )); for (I = 0; I <xnum; I ++) scanf ("% lf", & X [I], & Y [I]); (; I <xnum + ynum; I ++) scanf ("% lf", & X [I], & Y [I]); scanf ("% lf ", & V); For (INT I = 0; I <xnum; I ++) for (Int J = 0; j <ynum; j ++) {gra [I] [J] = SQRT (X [I]-X [J + xnum]) * (X [I]-X [J + xnum]) + (Y [I]-y [J + xnum]) * (Y [I]-y [J + xnum])/V; chose [CNT ++] = gra [I] [J];} Sort (chose, chose + CNT); printf ("%. 2lf \ n ", solve ();} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.