2012 Tianjin E-Question

Source: Internet
Author: User

Give us an n coordinate point and a distance d, indicating that the car is out of oil on M M.

Then choose a few points to establish the oil station, so that you can start from 1 to traverse all the points, and then back to 1. And it is required to have a petrol station at point 1, the cost of establishing a petrol station at point I is 2^ (i-1)

Because of the special nature of the cost, if the largest point can not be established, then certainly is not built. So first set up a petrol station at all points, see if you can traverse all the points, and then turn from the large to the small enumeration point to see if you can not establish a petrol station.

But how the card determines if it can traverse all the points.

First of all, all the oil station distance from the nearest oil station can not exceed D, if more than can not reach, and can not be through the point of no oil station relay

Then, not the point of the petrol station distance from the nearest oil station can not exceed D/2, this is obviously, if more than D/2, then from the petrol station to reach this point, there is no way to go back.

1#include <stdio.h>2#include <string.h>3#include <iostream>4#include <algorithm>5#include <queue>6#include <stack>7#include <math.h>8 using namespacestd;9 /*Ten Cost is 2^ (i-1) This is very special . One How to judge efficiently if you can pass all the points and go home?  A  */ - Const intINF =1<< -; - Const intN = -+Ten; the struct Point - { -     intx, y; -     DoubleDistConstPoint &RHS) +     { -         returnsqrt ((x-rhs.x) * (x-rhs.x) + (y-rhs.y) * (yrhs.y)); +     } A }a[n]; at intn,d; - intDist[n][n]; - intSta[n]; - BOOLVis[n]; - intCnt1,cnt2; - BOOLBFS () in { -memset (Vis,0,sizeof(Vis)); to     intTMP =0; +      for(intI=1; i<=n;++i) -TMP + =Sta[i]; theCnt1 =1; *Cnt2 =0; $vis[1] =true;Panax Notoginsengqueue<int>Q; -Q.push (1); the      while(!q.empty ()) +     { A         intU =Q.front (); Q.pop (); the          for(intI=2; i<=n;++i) +         { -             if(!sta[i])Continue; $             if(!vis[i] && dist[u][i]<=d) $             { - Q.push (i); -cnt1++; theVis[i] =true; -             }Wuyi         } the     } -      for(intI=1; i<=n;++i) Wu         if(Sta[i]) Q.push (i); -      while(!q.empty ()) About     { $         intU =Q.front (); Q.pop (); -          for(intI=2; i<=n;++i) -         { -             if(Sta[i])Continue; A             if(!vis[i] && dist[u][i]*2<=d) +             { theVis[i] =true; -cnt2++; $             } the         } the     } the     if(Cnt1==tmp && cnt2==n-tmp)return true; the  -     return false; in } the intMain () the { About     //freopen ("D:/in.txt", "R", stdin); the      while(SCANF ("%d%d", &n,&d)! =EOF) the     { the          for(intI=1; i<=n;++i) +         { -scanf"%d%d",&a[i].x,&a[i].y); theSta[i] =true;Bayi         } the          for(intI=1; i<=n;++i) the         { -              for(intj=1; j<=n;++j) -DIST[I][J] = dist[j][i] = (int) ceil (a[i].dist (a[j )); the         } the         if(BFS ()) the         { the  -              for(inti=n;i>=2;--i) the             { theSta[i] =false; the                 if(!BFS ())94Sta[i] =true; the             } the              while(sta[n]==0) n--; the              for(inti=n;i>=1;--i)98printf"%d", Sta[i]); AboutPuts""); -         }101         Else102Puts"-1");103     }104     return 0; the}

2012 Tianjin E-Question

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.