HDU 4435 charge-station () BFS graph theory problem

Source: Internet
Author: User

e-charge-stationTime limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i6 4u Submit Status Practice HDU 4435Appoint Description:

Description

There is n cities in M^3 ' s empire. M^3 owns a palace and a car and the palace resides in City 1. One day, she wants-to-travel around all the cities from her palace and finally back to her home. However, her car had limited energy and can only travel by no more than D meters. Before it is run out of the energy, it should is charged in some. Under M^3 ' s despotic power, the judge is forced to build several oil stations in some of the cities. The judge must build a oil station in City 1 and building other oil stations are up to his choice as long as m^3 can Succe Ssfully travel around all the cities.
Building An, in city I'll cost 2 i-1 MMMB. Please help the judge calculate out of the minimum cost to build the oil stations in order to fulfill m^3 ' s would.

Input

There is several test cases (no more than), each case begin with the integer N, D (the number of the cities and the Maximu M distance the car can run after charged, 0 < n≤128).
Then follows N lines and line I'll contain II numbers x, y (0≤x, y≤1000), indicating the coordinate of city I.
The distance between city I and City J would be Ceil (sqrt ((XI-XJ) 2 + (YI-YJ) 2)). (Ceil means rounding the number up, e.g. ceil (4.1) = 5)

Output

For each case, the output of the minimum cost to build of the oil stations in the binary form without leading zeros.
If it ' s impossible to visit all the cities even after all oil stations is build, output-1 instead.

Sample Input

3 30 00 30 13 20 00 30 13 10 00 30 116 2330 4037 5249 4952 6431 6252 3342 4152 4157 5862 4242 5727 6843 6758 4858 2737 69

Sample Output

11111-110111011

Hint

In case 1, the judge should select (0, 0) and (0, 3) as the which result in the visiting route:1->3->2- >3->1. And the cost is 2^ (1-1) + 2^ (2-1) = 3.
The proposal is to give the N and D, below the coordinates of n points, respectively, the car can be used to refuel a distance of D. But in the middle can refuel, ask where refueling can make the car to exercise a full round trip, and require the establishment of gas stations to spend the least amount,
Output is binary judgment, 1 for build, 0 for not established

1#include <stdio.h>2#include <iostream>3#include <string.h>4#include <queue>5#include <math.h>6#include <algorithm>7 using namespacestd;8 Const intmaxn= Max;9 Const intinf=999999999;Ten intMAP[MAXN][MAXN]; One intn,d; A DoubleX[MAXN],Y[MAXN]; - intDIS[MAXN]; - BOOLVIS[MAXN]; the  - intANS[MAXN]; -  - intCheck () { +memset (Vis,false,sizeof(Vis)); -        for(intI=1; i<=n;i++){ +           if(Ans[i]) Adis[i]=0; at           Else -dis[i]=inf; -       } -queue<int>que; -Que.push (1); -vis[1]=true; in      while(!Que.empty ()) { -        intu=Que.front (); to Que.pop (); +            for(intI=1; i<=n;i++){ -               if(!vis[i]&&map[u][i]<=d) { theDis[i]=min (dis[i],dis[u]+map[u][i]); *                    if(Ans[i]) { $vis[i]=true;Panax Notoginseng Que.push (i); -                    } the               } +           }           A     } the      for(intI=1; i<=n;i++){ +        if(ans[i]==1&&!Vis[i]) -            return false; $        Else if(ans[i]==0&&dis[i]*2>d) $            return false; -     } -   return true; the         - }Wuyi  the intMain () { -         while(SCANF ("%d%d", &n,&d)! =EOF) { Wumemset (Map,0,sizeof(map)); -               for(intI=1; i<=n;i++){ Aboutscanf"%LF%LF",&x[i],&y[i]); $              } -               for(intI=1; i<=n;i++){ -                  for(intj=1; j<=n;j++){ -Map[i][j]=ceil (sqrt ((X[I]-X[J)) * (X[i]-x[j]) + (Y[i]-y[j]) * (y[i]-Y[j] )); A                 } +              } the               for(intI=1; i<=n;i++){ -ans[i]=1; $              } the               if(!Check ()) { theprintf"-1\n"); the                 Continue;  the               } -  in                for(inti=n;i>=1; i--){ theans[i]=0; the                   if(!check ()) Aboutans[i]=1; the               } the             inti; the          for(i=n;i>=1; i--){ +             if(ans[i]==1) -                  Break; the         }Bayi          for(intj=i;j>=1; j--) theprintf"%d", Ans[j]); theprintf"\ n"); -        } -        return 0; the}

HDU 4435 charge-station () BFS graph theory problem

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.