//#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using lg = long long; #define TEST clog << "TEST" << endl #define IINF 2147483647 #define LLINF 9223372036854775807LL #define AMARI 998244353 #define TEMOTO ((sizeof(long double) == 16) ? false : true) #define TIME_LIMIT 950 * (TEMOTO ? 1 : 1000) #define el '\n' #define El '\n' //疑似乱数(XorShift) unsigned long xor128(void) { static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned long t = (x xor (x << 11)); x = y; y = z; z = w; return (w = (w xor (w >> 19)) xor (t xor (t >> 8))); } int wakusei_num, station_num; class planet { public: int x; int y; int num; int group; }; bool hikaku_rad(planet a, planet b) { return (atan2(a.y - 500, a.x - 500) < atan2(b.y - 500, b.x - 500)); } int planet_distance(planet const& a, planet const& b) { int ans = (a.x - b.x) * (a.x - b.x); ans += (a.y - b.y) * (a.y - b.y); return ans; } class space_station { public: int x; int y; int num; }; int output_lines = 0; vector wakusei(100); vector station(8); //a番目とa+1番目をswapすることを考える //距離の二乗の総和の大小を返すので、小さければ小さいほど良い int kinbou_hyouka(int a) { //(a-1,a)と(a+1,a+2)を引く if (a <= 0 || a + 2 >= 100)return IINF; int ans = -1 * planet_distance(wakusei[a - 1], wakusei[a]); ans -= planet_distance(wakusei[a + 1], wakusei[a + 2]); //(a-1,a+1)と(a,a+2)を足す ans += planet_distance(wakusei[a - 1], wakusei[a + 1]); ans += planet_distance(wakusei[a], wakusei[a + 2]); return ans; } void get_wakusei(void){ for (int i = 0; i < wakusei_num; i++) { cin >> wakusei[i].x >> wakusei[i].y; wakusei[i].num = i; } } void k_means(int k = 8) { for (int i = 0; i < wakusei_num; i++) { wakusei[i].group = i % k; } bool henkou = true; vector kosuu(8, 0), xsum(8, 0), ysum(8, 0),xave(8),yave(8); int cnt = 0; while (henkou) { henkou = false; //それぞれのグループの平均点を求める for (int i = 0; i < wakusei_num; i++) { kosuu[wakusei[i].group]++; xsum[wakusei[i].group] += wakusei[i].x; ysum[wakusei[i].group] += wakusei[i].y; } for (int i = 0; i < station_num; i++) { if (kosuu[i]) { xave[i] = xsum[i] / kosuu[i]; yave[i] = ysum[i] / kosuu[i]; } } //それぞれの点から、最も近いグループ重心を求める for (int i = 0; i < wakusei_num; i++) { int minvalue = IINF, minsoeji; for (int j = 0; j < 8; j++) { if (minvalue > (xave[j] - wakusei[i].x) * (xave[j] - wakusei[i].x) + (yave[j] - wakusei[i].y) * (yave[j] - wakusei[i].y)) { minvalue = (xave[j] - wakusei[i].x) * (xave[j] - wakusei[i].x) + (yave[j] - wakusei[i].y) * (yave[j] - wakusei[i].y); minsoeji = j; } } if (wakusei[i].group != minsoeji) { wakusei[i].group = minsoeji; henkou = true; } } cnt++; } clog << "k-means loop kaisuu is " << cnt << el; for (int i = 0; i < 8; i++) { station[i].x = xave[i]; station[i].y = yave[i]; station[i].num = i; } return; } void print_keiro(void) { output_lines = wakusei_num * 2 + station_num + 1; cout << output_lines << el; bool temp = false; cout << "1 1" << el; for (int i = wakusei[0].group; !temp || i != wakusei[0].group; i++) { for (int j = 1; j < wakusei_num; j++) { if (wakusei[j].group == i) { cout << "2 " << station[i].num + 1 << el; cout << "1 " << wakusei[j].num + 1 << el; } } cout << "2 " << station[i].num + 1 << el; if (i == 7)i -= 8; temp = true; } cout << "2 " << wakusei[0].group + 1 << el; cout << "1 1" << el; } void print_station(void) { for (int i = 0; i < station_num; i++) { cout << station[i].x << ' ' << station[i].y << el; } } #define MULTI_TEST_CASE false void solve(void) { cin >> wakusei_num >> station_num; get_wakusei(); if (TEMOTO)clog << el << el; clock_t start = clock(); k_means(8); print_station(); print_keiro(); return; } void calc(void) { return; } int main(void) { cin.tie(nullptr); ios::sync_with_stdio(false); int t = 1; if (MULTI_TEST_CASE)cin >> t; while (t--) { solve(); } calc(); return 0; }