#include #define rep(i,n) for(int i=0; i=0; i--) #define pers(i,n,s) for(int i=n-1; i>=s; i--) #define all(v) v.begin(),v.end() #define fi first #define se second #define pb push_back #define si(v) int(v.size()) #define lb(v,n) lower_bound(all(v),n) #define lbi(v,n) int(lower_bound(all(v),n) - v.begin()) #define ub(v,n) upper_bound(all(v),n) #define ubi(v,n) int(upper_bound(all(v),n) - v.begin()) #define mod 1000000007 #define infi 1010000000 #define infl 1100000000000000000 #define outve(v) {for(auto i : v) cerr << i << " ";cerr << endl;} #define outmat(v) for(auto i : v){for(auto j : i) cerr << j << " ";cerr << endl;} #define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];} #define IN(n,m,v) rep(i,n) rep(j,m){cin >> v[i][j];} #define cyes cout << "Yes" << endl #define cno cout << "No" << endl #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define csp << " " << #define outset(n) cout << fixed << setprecision(n); using namespace std; using ll = long long; using ull = unsigned long long; using uint = unsigned int; using ld = long double; using vi = vector; using vvi = vector>; using vd = vector; using vvd = vector>; using vl = vector; using vvl = vector>; using vs = vector; using pii = pair; using pll = pair; template using ve = vector; template using vv = vector>; template using pq2 = priority_queue; template using pq1 = priority_queue,greater>; template bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;} template bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;} int popcnt(uint n) {return __builtin_popcount(n);} int popcntl(ull n) {return __builtin_popcountll(n);} int bsr(uint n) {return 31 - __builtin_clz(n);} int bsrl(ull n) {return 63 - __builtin_clzll(n);} int bsf(uint n) {return __builtin_ctz(n);} int bsfl(ull n) {return __builtin_ctzll(n);} const int LOCAL = 0; double TIME_LIMIT = 0.9; unsigned int xorshift() { static unsigned int tx = 123456789, ty=362436069, tz=521288629, tw=88675123; unsigned int tt = (tx^(tx<<11)); tx = ty; ty = tz; tz = tw; return ( tw=(tw^(tw>>19))^(tt^(tt>>8)) ); } class Solver { int N,M; vl planet_x,planet_y,station_x,station_y; ll alpha; int max_xy = 1001; int ti; double time; ll score; public: Solver(){ ti = clock(); alpha = 5; cin >> N >> M; planet_x.resize(N); planet_y.resize(N); rep(i,N) cin >> planet_x[i] >> planet_y[i]; station_x.assign(M,0); station_y.assign(M,0); score = -infl; } inline ll cal_dist(ll x0, ll y0, ll x1, ll y1){ return (x1-x0)*(x1-x0) + (y1-y0)*(y1-y0); } void solve(){ time = 1.0 * (clock() - ti) / CLOCKS_PER_SEC; int loop = 0; //rep(i,M) station_x[i] = xorshift()%max_xy, station_y[i] = xorshift()%max_xy; rep(i,M) station_x[i] = int(500+500*sin(i*2.0*acos(-1)/M)), station_y[i] = int(500+500*cos(i*2.0*acos(-1)/M)); double T1 = 800, T0 = 0; double T = T1; while(time < TIME_LIMIT){ loop++; ll score0 = score; int change_n = xorshift()%M; int station_x0 = station_x[change_n]; int station_y0 = station_y[change_n]; int dd = 50 + (10-50)/TIME_LIMIT*time; int dx = xorshift()%dd*(xorshift()%2==0 ? -1:1), dy = xorshift()%dd*(xorshift()%2==0 ? -1:1); station_x[change_n] += dx,station_y[change_n] += dy; chmin(station_x[change_n],1000ll), chmin(station_y[change_n],1000ll); chmax(station_x[change_n],0ll), chmax(station_y[change_n],0ll); int change_n1 = xorshift()%M; while (change_n == change_n1) { change_n1 = xorshift()%M; } int station_x1 = station_x[change_n1]; int station_y1 = station_y[change_n1]; dx = xorshift()%dd*(xorshift()%2==0 ? -1:1), dy = xorshift()%dd*(xorshift()%2==0 ? -1:1); station_x[change_n1] += dx,station_y[change_n1] += dy; chmin(station_x[change_n1],1000ll), chmin(station_y[change_n1],1000ll); chmax(station_x[change_n1],0ll), chmax(station_y[change_n1],0ll); vi neigbor(N,-1); vl d_planet_station(N,0); rep(i,N){ ll d = infl; rep(j,M) if(chmin(d, cal_dist(station_x[j],station_y[j],planet_x[i],planet_y[i]))) neigbor[i] = j; d_planet_station[i] = d; } /* vvl D(M,vl(M,0)); rep(i,M) reps(j,i+1,M) D[i][j] = D[j][i] = cal_dist(station_x[i],station_y[i],station_x[j],station_y[j]); vvl dp(int(1< cal_dist(planet_x[p0],planet_y[p0],planet_x[p1],planet_y[p1])*alpha*alpha+d_planet_station[p1]*alpha){ d += cal_dist(planet_x[p0],planet_y[p0],planet_x[p1],planet_y[p1])*alpha*alpha + d_planet_station[p1]*alpha; }else{ d += d_planet_station[p0]*alpha; } break; } int p0 = P[I[(iii+s)%si(P)]]; int p1 = P[I[(iii+s+1)%si(P)]]; if((d_planet_station[p0]+d_planet_station[p1])*alpha > cal_dist(planet_x[p0],planet_y[p0],planet_x[p1],planet_y[p1])*alpha*alpha){ d += cal_dist(planet_x[p0],planet_y[p0],planet_x[p1],planet_y[p1])*alpha*alpha; }else{ d += (d_planet_station[p0]+d_planet_station[p1])*alpha; } } score1 += d; } score1 = ll(1000000000.0/(1000.0+sqrt(double(score1)))); if(score0 < score1){ score = score1; }else{ if((double)(xorshift()%infi)/(double)infi < exp((score1-score0)/T)){ score = score1; }else{ station_x[change_n] = station_x0; station_y[change_n] = station_y0; station_x[change_n1] = station_x1; station_y[change_n1] = station_y1; } } time = 1.0 * (clock() - ti) / CLOCKS_PER_SEC; if(LOCAL) time *= 2; T = T1 + (T0-T1)/(TIME_LIMIT) * (time); if(LOCAL && loop%100 == 0) cerr << loop csp score csp score1 csp time csp T << endl; } time = 1.0 * (clock() - ti) / CLOCKS_PER_SEC; if(LOCAL) cerr << loop csp score csp time << endl; print_ans(); } void print_ans(){ rep(i,M) cout << station_x[i] csp station_y[i] << endl; vi t,r; vi neigbor(N,-1); vl d_planet_station(N,0); rep(i,N){ ll d = infl; rep(j,M) if(chmin(d, cal_dist(station_x[j],station_y[j],planet_x[i],planet_y[i]))) neigbor[i] = j; d_planet_station[i] = d; } vvl D(M,vl(M,0)); rep(i,M) reps(j,i+1,M) D[i][j] = D[j][i] = cal_dist(station_x[i],station_y[i],station_x[j],station_y[j]); vvl dp(int(1<= 0){ int s0 = s; s = from[bit][s]; station_ord.pb(s); bit ^= int(1< cal_dist(planet_x[p0],planet_y[p0],planet_x[p1],planet_y[p1])*alpha*alpha+d_planet_station[p1]*alpha){ t.pb(1); r.pb(p1); t.pb(2); r.pb(station); }else{ t.pb(2); r.pb(station); } break; } int p0 = P[I[(iii+s)%si(P)]]; int p1 = P[I[(iii+s+1)%si(P)]]; if((d_planet_station[p0]+d_planet_station[p1])*alpha > cal_dist(planet_x[p0],planet_y[p0],planet_x[p1],planet_y[p1])*alpha*alpha){ t.pb(1); r.pb(p1); }else{ t.pb(2); r.pb(station); t.pb(1); r.pb(p1); } } } t.pb(2); r.pb(neigbor[0]); t.pb(1); r.pb(0); cout << si(r) << endl; rep(i,si(r)) cout << t[i] csp r[i]+1 << endl; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); Solver solver; solver.solve(); return 0; }