2013
12-25

# Subway planning

The government in a foreign country is looking into the possibility of establishing a subway system in its capital. Because of practical reasons, they would like each subway line to start at the central station and then go in a straight line in some angle as far as necessary. You have been hired to investigate whether such an approach is feasible. Given the coordinates of important places in the city as well as the maximum distance these places can be from a subway station (possibly the central station, which is already built), your job is to calculate the minimum number of subway lines needed. You may assume that any number of subway stations can be
built along a subway line.

Figure 1: The figure above corresponds to the first data set in the example input.

The first line in the input file contains an integer N, the number of data sets to follow. Each set starts with two integers, n and d (1 <= n <= 500, 0 <= d < 150). n is the number of important places in the city that must have a subway station nearby, and d is the maximum distance allowed
between an important place and a subway station. Then comes n lines, each line containing two integers x and y (-100 <= x, y <= 100), the coordinates of an important place in the capital. The central station will always have coordinates 0, 0. All pairs of coordinates within a data set
will be distinct (and none will be 0, 0).

The first line in the input file contains an integer N, the number of data sets to follow. Each set starts with two integers, n and d (1 <= n <= 500, 0 <= d < 150). n is the number of important places in the city that must have a subway station nearby, and d is the maximum distance allowed
between an important place and a subway station. Then comes n lines, each line containing two integers x and y (-100 <= x, y <= 100), the coordinates of an important place in the capital. The central station will always have coordinates 0, 0. All pairs of coordinates within a data set
will be distinct (and none will be 0, 0).

2
7 1
-1 -4
-3 1
-3 -1
2 3
2 4
2 -2
6 -2
4 0
0 4
-12 18
0 27
-34 51

4
2

【前言】

xlj问我有没有题做，没有的话给我一道。

hdu1922这道题只有几个人过了这道题，解题报告也找不到。

xlj回来后继续，但是sample还没过。

【思路】

【代码】

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

#define min(a,b) ((a)<=(b)?(a):(b))

const int maxn = 1000;
const double pi = acos(-1.0);

struct point
{
double x, y;
double l, r;
}pt[maxn*2+1];

bool cmp(const point &a, const point &b)
{
return a.l<b.l;
}

void set(point &p, double d, double dis)
{
double a, b;
if (p.x==0)
{
if (p.y>0) a = 0.5*pi;
else a = 1.5*pi;
}
else if (p.y==0)
{
if (p.x>0) a = 0;
else a = pi;
}
else
{
a = asin(fabs(p.y*1.0)/dis);
if (p.x<0 && p.y>=0) a = pi - a;
else if (p.x<=0 && p.y<0) a += pi;
else if (p.x>0 && p.y<=0) a = 2*pi-a;
}
b = asin(1.0*d/dis);
p.l = a-b;
p.r = a+b;
}

double dist(double x, double y)
{
return sqrt(x*x+y*y);
}

int main()
{
int t;
int n;
double d;
int i, j;
int ct;
double d1;
scanf("%d", &t);
while(t--)
{
scanf("%d %lf", &n, &d);
for (i=0; i<n; i++)
{
scanf("%lf %lf", &pt[i].x, &pt[i].y);
d1 = dist(pt[i].x, pt[i].y);
if (d1<=d)
{
i--;
n--;
}
else set(pt[i], d, d1);
}
sort(pt, pt+n, cmp);
for (i=n; i<2*n; i++)
{
pt[i].l = pt[i-n].l+2*pi;
pt[i].r = pt[i-n].r+2*pi;
}
int ans = 1000000;
for (j=0; j<n; j++)
{
ct = 1;
double s = pt[j].r;
for (i=1+j; i<n+j; i++)
{
if (s<pt[i].l)
{
ct++;
s = pt[i].r;
}
else
{
s = min(s, pt[i].r);
}
}
ans = min(ans, ct);
}
if (ans==1000000) ans = 0;
printf("%d\n", ans);
}
return 0;
}

1. 在方法1里面：

//遍历所有的边，计算入度
for(int i=0; i<V; i++)
{
degree = 0;