#include #include #include using namespace std; typedef long double LD; typedef vector VLD; LD EPS = 1e-8; LD pockets_x[6] = {0, 54, 108, 0, 54, 108}; LD pockets_y[6] = {0, 0, 0, 54, 54, 54}; // computational geometry struct PT { LD x, y; PT(LD x, LD y) : x(x), y(y) {} PT operator+(const PT &p) const { return PT(x+p.x, y+p.y); } PT operator-(const PT &p) const { return PT(x-p.x, y-p.y); } PT operator*(const LD c) const { return PT(c*x, c*y); } }; LD dot(const PT &p, const PT &q) { return p.x*q.x + p.y*q.y; } LD dist2(const PT &p, const PT &q) { return dot(p-q,p-q); } PT ProjectPointSegment(const PT &a, const PT &b, const PT &c) { LD r = dot(b-a,b-a); if (fabs(r) < EPS) return a; r = dot(c-a,b-a)/r; if (r < 0) return a; if (r > 1) return b; return a + (b-a)*r; } bool Collision(const LD ax, const LD ay, const LD bx, const LD by, const LD cx, const LD cy) { PT p = ProjectPointSegment(PT(ax,ay), PT(bx,by), PT(cx,cy)); return (sqrt(dist2(p,PT(cx,cy))) <= 2-EPS); } bool CanHit(const LD xc, const LD yc, const LD xt, const LD yt, const LD xp, const LD yp, const VLD &x, const VLD &y) { // compute direction vector from pocket to target ball LD dx = xt - xp, dy = yt - yp; LD d = sqrt(dx*dx+dy*dy); dx /= d; dy /= d; // compute final position of cue ball LD xf = xt + 2*dx, yf = yt + 2*dy; // bad if less than 90 degrees if (dot(PT(xc-xf,yc-yf),PT(dx,dy)) <= EPS) return false; // bad if cue ball outside (not necessary) if (xf < -EPS || yf < -EPS || xf > LD(108)+EPS || yf > LD(54)+EPS) return false; // check for collisions with balls for (size_t i = 0; i < x.size(); i++) { if (Collision(xc, yc, xf, yf, x[i], y[i])) return false; if (Collision(xt, yt, xp, yp, x[i], y[i])) return false; } return true; } void FindShots(const LD xc, const LD yc, const LD xt, const LD yt, const VLD &x, const VLD &y) { int pockets_hit = 0; for (int p = 0; p < 6; p++) { if (CanHit(xc, yc, xt, yt, pockets_x[p], pockets_y[p], x, y)) { if (pockets_hit > 0) cout << " "; cout << p+1; pockets_hit++; } } if (pockets_hit == 0) cout << "no shot"; cout << endl; } int main() { while (1) { LD xc, yc, xt, yt; cin >> xc; if (xc == 0) break; cin >> yc >> xt >> yt; int n; cin >> n; VLD x(n); VLD y(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; FindShots(xc, yc, xt, yt, x, y); } return 0; }