#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using vec_int = vector; using P = pair; using T = tuple; using ll = long long; // using PQ = priority_queue, vector>, greater>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) float initial_T = 100000; float final_T = 20; float TIME_LIMIT = 1000; float TIME_LIMIT_STATION = 200; int RAND_ARR_LEN = 100000; int RAND_RANGE = 1000000000; int N_VERTICAL = 10; vector

DIRS = {make_pair(0, -1), make_pair(-1, 0), make_pair(0, 1), make_pair(1, 0)}; bool is_in(int x, int y, int N) { if (x >= 0 && x < N && y >= 0 && y < N) return true; return false; } // std::mt19937 mt{ std::random_device{}() }; std::mt19937 mt{12345}; std::uniform_int_distribution dist(1, RAND_RANGE); float get_time(bool init) { static std::chrono::system_clock::time_point start; if (init) { start = std::chrono::system_clock::now(); } std::chrono::system_clock::time_point end = std::chrono::system_clock::now(); return std::chrono::duration_cast(end - start).count(); //処理に要した時間をミリ秒に変換 } class Rand { private: int count = 0; vec_int rand_arr; public: Rand(){ rep(i, RAND_ARR_LEN){ rand_arr.push_back(dist(mt)); } } ; int get(); int get_rand(int from, int to); float get_float(); } ; int Rand::get() { int num = rand_arr.at(count); count += 1; count %= RAND_ARR_LEN; return num; } int Rand::get_rand(int from, int to) { int diff = to - from; int num = get() % diff; return num + from; } float Rand::get_float() { // 0~1の間の一様乱数 return (float)get() / (float)RAND_RANGE; } Rand ro; float current_tmp_station(float current_time) { return final_T + (initial_T - final_T) * (TIME_LIMIT_STATION - current_time) / TIME_LIMIT_STATION; } bool is_valid_transition_station(int diff, float current_time) { float t = current_tmp_station(current_time); float rand = ro.get_float(); // cerr<<"tmperature"< &stations){ int result = 0; rep(i, N){ int tmp_dist = INT_MAX; rep(j, M){ tmp_dist = min(tmp_dist, stations.at(j).square_distance(a.at(i), b.at(i))); } result += tmp_dist; } return result; } void cout_ans(vector

&ans){ cout<>>> make_dist_map(vector &stations){ vector>>> result(N, vector>>(N+M)); for(int i=0;i visited(N+M, 0); vector prev_city(N, -1); priority_queue, greater> pq; pq.emplace(0, i, -1); while(!pq.empty()){ int dist, pos, prev; tie(dist, pos, prev) = pq.top(); pq.pop(); if(visited.at(pos)==1)continue; if(pos route; if(prev!=-1){ route = result.at(i).at(prev).second; } route.push_back(make_pair(1, pos)); result.at(i).at(pos) = make_pair(dist, route); for(int j=0;j route; if(prev!=-1){ route = result.at(i).at(prev).second; } route.push_back(make_pair(2, pos-N)); result.at(i).at(pos) = make_pair(dist, route); for(int j=0;j &ans, vector &stations, vector>>> &dist_mat){ // 訪れていない場所の中で一番コストが小さくいけそうなところにいく int pos = 0; ans.push_back(make_pair(1, 0)); vec_int visited(N, 0); while(true){ visited.at(pos) = true; int min_dist = INT_MAX; int next_pos = -1; for(int i=0;itmp_dist){ min_dist = tmp_dist; next_pos = i; } } if(next_pos==-1)break; for(auto p_pos: dist_mat.at(pos).at(next_pos).second){ ans.push_back(p_pos); } pos = next_pos; } for(auto p_pos: dist_mat.at(pos).at(0).second){ ans.push_back(p_pos); } } int main(){ get_time(true); cin>>N>>M; rep(i, N){ int aa, bb; cin>>aa>>bb; a.push_back(aa); b.push_back(bb); } vector stations(M); rep(i, M){ stations.at(i) = SpaceStation(ro.get_rand(0, 1001), ro.get_rand(0, 1001)); } int station_score = tot_distance(stations); cerr<<"initial tot square distance:"<TIME_LIMIT_STATION)break; int selected_station = ro.get_rand(0, M); int old_x = stations.at(selected_station).x; int old_y = stations.at(selected_station).y; stations.at(selected_station).random_move(); int new_score = tot_distance(stations); int diff = new_score-station_score; if(is_valid_transition_station(-1*diff, ct)){//小さくなる方がいい station_score = new_score; }else{ stations.at(selected_station).set_pos(old_x, old_y); } } vector>>> dist = make_dist_map(stations); /* rep(i, N){ sort(dist.at(i).begin(), dist.at(i).end()); } */ rep(i, M){ cout< ans; greedy_strategy(ans, stations, dist); cout_ans(ans); return 0; }