?? pku2695.cpp
字號:
#include <stdio.h>
#include <math.h>
typedef struct
{
double x;
double y;
} Point;
Point p[100], dis, lasdis;
double dot(Point a, Point b, Point c)
{
return a.x * (c.x - b.x) + a.y * (c.y - b.y);
}
double Dot(Point a, Point b, Point c)
{
return (c.x - b.x) * (b.x - a.x) + (c.y - b.y) * (b.y - a.y);
}
double calcdis(Point a, Point b)
{
return sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) );
}
int main()
{
double D, nextcos, tmpcos, tmpdis, tmpdot;
int N, S, i, j, nextid;
// freopen("2695.in", "r", stdin);
while (scanf("%lf %lf %d %d %lf", &dis.x, &dis.y, &N, &S, &D) != -1)
{
lasdis.x = dis.x;
lasdis.y = dis.y;
if (fabs(dis.x) < 1e-6 && fabs(dis.y) < 1e-6 && N == 0 && S == 0 && fabs(D) < 1e-6)
{
break;
}
for (i = 0; i < N; i++)
{
scanf("%lf %lf", &p[i].x, &p[i].y);
}
do
{
printf("%d ", S);
S--;
nextid = -1;
nextcos = 0;
for (i = 0; i < N; i++)
{
if (i == S)
{
continue;
}
tmpdis = calcdis(p[S], p[i]);
tmpdot = dot(dis, p[S], p[i]);
tmpcos = tmpdot / tmpdis;
if (tmpdot <= 0 || tmpdis > D || dot(lasdis, p[S], p[i]) < 0)
{
continue;
}
if (tmpcos > nextcos)
{
nextcos = tmpcos;
nextid = i;
}
}
if (nextid == -1)
{
break;
}
lasdis.x = p[nextid].x - p[S].x;
lasdis.y = p[nextid].y - p[S].y;
S = nextid + 1;
}
while (nextid != -1);
printf("\n");
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -