Language: C++

#include<complex>
#include<vector>
#include<iostream>
#include<stack>
#include<cmath>
#include<fstream>
#include<cstdio>
#include<iomanip>

enum CCW{FRONT=0x01,RIGHT=0x02,BACK=0x04,LEFT=0x08,OVER=0x10};
enum CIRCLE_RELATION{CIRCLE_SAME=0x01,CIRCLE_CONTAIN=0x02,
		     CIRCLE_NO_CROSS=0x04,CIRCLE_ONE_CROSS=0x08,
		     CIRCLE_ONE_INSIDE_CROSS=0x10,CIRCLE_TWO_CROSS=0x20};
#define sc second
#define fr first
 
using namespace std;
 
typedef double elem;
typedef complex<elem> point, vec;
typedef pair<point, point> line, hline, seg, pp;
 
const double infty = 1e40;
const double eps = 1.0e-8;
const double pi = acos(-1.0);
point base(0,0);
  
inline elem sq(elem a){ return a*a; }
inline elem cq(elem a){ return a*a*a; }
elem rad(elem deg){ return (deg/180)*pi; }
elem deg(elem rad){ return (rad*180)/pi; }
bool eq(elem a, elem b){ return abs(a-b) < eps; }
bool eqv(vec a, vec b){ return eq( abs(b-a),0); }
bool far(point a, point b){ return abs(b-a)>0; }
bool near(point a, point b){ return abs(b-a)<=0; }
elem dot(vec a, vec b){ return (a.real() * b.real() + a.imag() * b.imag() ); }
elem cross(vec a, vec b){ return ( a.real() * b.imag() - a.imag() * b.real() ); }

elem varg(vec a, vec b){
  elem ret=arg(a)-arg(b);
  if(ret<0)ret+=2*pi;
  if(ret>2*pi)ret-=2*pi;
  if(eq(ret,2*pi))ret=0;
  return ret;
}
elem varg2(vec a, vec b){
  elem ret = varg(a,b);
  if(ret>pi)return 2*pi-ret;
  return ret;
}
elem arg(vec a, vec b){ return acos( dot(a,b) / ( abs(a) * abs(b) ) ); }
point rot(point p, elem theta){ return p * polar((elem)1.0, theta); }

vec uvec(vec a){ return a / abs(a); }
vec nmr(vec a){ return a * vec(0,-1); }
vec nml(vec a){ return a * vec(0,1); }
vec unmr(vec a){ return uvec( nmr(a) ); }
vec unml(vec a){ return uvec( nml(a) ); }

inline int ccw(const point &a, point b, point x){
  b -= a;
  x -= a;
  if( eq(cross(b,x),0.0) && dot(b,x) < 0 ) return BACK;
  if( eq(cross(b,x),0.0) && abs(b) < abs(x) ) return FRONT;
  if( eq(cross(b,x),0.0) ) return OVER;
  if( cross(b,x) > 0 ) return LEFT;
  if( cross(b,x) < 0 ) return RIGHT;
}

struct circle{
  point c;
  elem r;
  circle():c(point(0,0)),r(0){}
  circle(point c, elem r):c(c),r(r){}
  bool incircle(point t){
    return abs(t-c)<=r;
  }
};

bool cmpYx(const point &a, const point &b){
  if( eq(a.imag(),b.imag()) ) return a.real()<b.real();
  if( a.imag()<b.imag() ) return true;
  return false;
}
bool cmpXy(const point &a, const point &b){
  if( eq(a.real(),b.real() ) ) return a.imag()<b.imag();
  if( a.real()<b.real() ) return true;
  return false;
}

int circlesRel(circle c1, circle c2){
  elem d=abs(c1.c-c2.c);
  elem r1=c1.r;
  elem r2=c2.r;
  if(r1<r2)swap(r1,r2);
  if(eq(d,r1+r2))return CIRCLE_ONE_CROSS;
  if(eq(d,r1-r2))return CIRCLE_ONE_INSIDE_CROSS;
  if(d>r1+r2)return CIRCLE_NO_CROSS;
  if(d<r1-r2)return CIRCLE_CONTAIN;
  if(d<r1+r2)return CIRCLE_TWO_CROSS;
  if(near(c1.c,c2.c)&&eq(c1.r,c2.r))return CIRCLE_SAME;
}

int intersectionCC(circle c1, circle c2, pp &p)
{
  if( !( circlesRel( c1, c2 ) & (CIRCLE_ONE_INSIDE_CROSS | CIRCLE_ONE_CROSS | CIRCLE_TWO_CROSS) ) ) return 0;
 
  elem d = abs(c1.c-c2.c);
  vec ab = c2.c - c1.c;
  elem k = ( sq( c1.r ) - sq( c2.r ) + sq( d ) ) / ( 2 * sq( d ) );
  point t = k * ab + c1.c;
  elem x = sqrt( sq(c1.r) - sq( d * k ) );
 
  if( eq( x, 0 ) ){
    p.first = t; return 1;
  }else{
    p.first = x * unml(ab) + t;
    p.second = x * unmr(ab) + t;
    return 2;
  }
}

void andrewConvexHull(const vector<point> &Q, vector<point> &CH)
{
  vector<point> T = Q;
  int n = T.size(), k = 0;
  sort( T.begin(), T.end(), cmpXy );
  CH.resize(2*n);
  for(int i = 0; i < n; CH[k++] = T[i++]){
    while( k >= 2 && ccw( CH[k-2], CH[k-1], T[i] ) & ( RIGHT | BACK ) ) --k;
  }
  for(int i = n-2, t = k+1; i >= 0; CH[k++] = T[i--] ){
    while( k >= t && ccw( CH[k-2], CH[k-1], T[i] ) & ( RIGHT | BACK ) ) --k;
  }
  CH.resize(k-1);
}

void drawLine(ofstream &ofs, const line &l){
  ofs <<
    "line(" << l.fr.real() << ',' << l.fr.imag() << ',' <<
    l.sc.real() << ',' << l.sc.imag() << ");" << endl;
}

int main()
{
  int N;
  elem P;
  int Q;
  //ofstream vis("vis");

  while(cin >> N >> P >> Q){
    if( N == 0 ) break;

    int init;
    int n_touch = 0;
    vector<point> in;
    vector<point> vp;
    circle c(point(0,0),P);
    
    for(int i = 0; i < N; ++i){
      elem x, y;
      cin >> x >> y;
      vp.push_back(point(x, y));
    }

    for(int i = 0; i < N; ++i){
      if( eq(abs(vp[i]), P) )
	init = n_touch = i;
    }
    
    for(int i = 0; i < Q; ++i){
      int touch;
      point fix = vp[n_touch];
      elem min_rot_arg = 4*pi;
      point is;
      
      for(int j = 0; j < N; ++j){
	if( n_touch != j ){
	  circle t(fix, abs(vp[j] - fix));
	  pp tis;
	  point tmp;
	  
	  intersectionCC(c,t,tis);
	  if( ccw(fix, point(0,0), tis.fr) == LEFT ) tmp=tis.fr;
	  if( ccw(fix, point(0,0), tis.sc) == LEFT ) tmp=tis.sc;
	  double t_arg = varg2(vp[j]-fix, tmp-fix);

	  if( eq(min_rot_arg, t_arg) ){
	    if( varg(vp[n_touch],tmp) > varg(vp[n_touch],is ) ){
	      touch = j;
	      is = tmp;
	    }
	  }else if( min_rot_arg > t_arg ){
	    min_rot_arg = t_arg;
	    touch = j;
	    is = tmp;
	  }
	  
	}
      }

      cout << fixed << setprecision(12) <<
	is.real() << ' ' << is.imag() << endl;
      /*
      for(int j = 0; j < N; ++j){
	drawLine(vis,line(vp[j],vp[(1+j)%N]));
      }
      vis << endl;
      */
      for(int j = 0; j < N; ++j){
	if(far(vp[j],fix))
	  vp[j] = rot(vp[j]-fix, min_rot_arg)+fix;
      }
      n_touch = touch;
    }
    /*
      for(int j = 0; j < N; ++j){
      drawLine(vis,line(vp[j],vp[(1+j)%N]));
      }
      vis << endl;
    */
    //cout << endl;
  }
  //vis.close();
  return 0;
}

Compiler output:
a.cc: In function 'void andrewConvexHull(const std::vector<std::complex<double> >&, std::vector<std::complex<double> >&)':
a.cc:127:3: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
  127 |   sort( T.begin(), T.end(), cmpXy );
      |   ^~~~
      |   sqrt
a.cc: In function 'int circlesRel(circle, circle)':
a.cc:102:1: warning: control reaches end of non-void function [-Wreturn-type]
  102 | }
      | ^
a.cc: In function 'int ccw(const point&, point, point)':
a.cc:68:1: warning: control reaches end of non-void function [-Wreturn-type]
   68 | }
      | ^