HDU 4435 charge-station (violence + judgment)

Source: Internet
Author: User

The main idea: to give you some points, they can connect, if the distance is more than D then go through the gas station, the cost of establishing a gas station for the first point is 2^ (i-1). Minimum cost, the minimum cost of the output binary representation.

The cost and sum are the worst equals =2^0+2^1+......+2^ (n-1). So the highest bit is 0 this number will be the smallest, from the highest bit of violence enumeration if the figure is connected after deleting this point, then it can be deleted, otherwise not.

When the graph is connected, it can be solved by explosion search, and can also be searched and set.

Charge-stationTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1053 Accepted Submission (s): 554


Problem Descriptionthere 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 2i-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.

Inputthere is several test cases (no more than), each case begin with the integer N, D (the number of the cities and the M Aximum 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)

Outputfor 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-110111011Hintin case 1, the judge should select (0, 0) and (0, 3) as the oil station which result in the VI Siting route:1->3->2->3->1. And the cost is 2^ (1-1) + 2^ (2-1) = 3.

Source2012 Asia Tianjin Regional Contest
#include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include < iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include < time.h> #include <stack> #include <map> #include <set> #define EPS 1e-8///#define LL long Long#define LL __int64#define INF 0x3f3f3f#define PI 3.1415926535898#define mod 1000000007using namespace std;const int maxn = 210;boo L vis[maxn];int mp[maxn][maxn];struct node{int x, y;} f[maxn];int N, d;double Dis (int a, int b) {return sqrt (((F[a] . x-f[b].x) * (f[a].x-f[b].x) + (F[A].Y-F[B].Y) * (F[A].Y-F[B].Y)) *1.0);}    BOOL BFs () {bool FLAG[MAXN];    int DIS[MAXN];    Memset (flag, false, sizeof (flag));            for (int i = 1; I <= n; i++) {if (Vis[i]) {dis[i] = 0;        Continue    } Dis[i] = INF;    } queue<int> que;    Que.push (1);    Flag[1] = true; while (!que.empty ()) {int x = Que.Front ();        Que.pop ();            for (int i = 1; I <= n; i++) {if (Flag[i] | | mp[x][i] > D) continue;            Dis[i] = min (Dis[i], dis[x]+mp[x][i]);                if (Vis[i]) {Flag[i] = true;            Que.push (i);        }}} for (int i = 1; I <= n; i++) {if (Vis[i] &&!flag[i]) return false;    if (!vis[i] && 2*dis[i] > D) return false; } return true;  int main () {while (~SCANF ("%d%d", &n, &d)) {for (int i = 1; I <= n; i++) scanf ("%d%d", &f[i].x,        &AMP;F[I].Y);        for (int i = 1; l <= N; i++) for (int j = 1; J <= N; j + +) Mp[i][j] = Ceil (Dis (i, j));        for (int i = 1; I <= n; i++) vis[i] = true;            if (!bfs ()) {cout<<-1<<endl;        Continue            } for (int i = n; I >= 1; i--) {vis[i] = false;        if (!bfs ()) vis[i] = true;   }     int x = n;        while (!vis[x]) x--;        for (int i = x; I >= 1; i--) cout<<vis[i];    cout<<endl; } return 0;}


HDU 4435 charge-station (violence + judgment)

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.