結果

問題 No.5007 Steiner Space Travel
ユーザー ococonomy1ococonomy1
提出日時 2023-04-27 01:32:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 4,994 bytes
コンパイル時間 1,188 ms
コンパイル使用メモリ 114,064 KB
実行使用メモリ 4,372 KB
スコア 5,907,215
最終ジャッジ日時 2023-04-27 01:32:07
合計ジャッジ時間 3,546 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 2 ms
4,368 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 2 ms
4,368 KB
testcase_15 AC 2 ms
4,368 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 2 ms
4,372 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 2 ms
4,372 KB
testcase_22 AC 2 ms
4,368 KB
testcase_23 AC 2 ms
4,368 KB
testcase_24 AC 2 ms
4,368 KB
testcase_25 AC 2 ms
4,372 KB
testcase_26 AC 2 ms
4,372 KB
testcase_27 AC 2 ms
4,372 KB
testcase_28 AC 2 ms
4,368 KB
testcase_29 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void k_means(int)’ 内:
main.cpp:121:34: 警告: ‘minsoeji’ may be used uninitialized [-Wmaybe-uninitialized]
  121 |                 wakusei[i].group = minsoeji;
main.cpp:113:34: 備考: ‘minsoeji’ はここで定義されています
  113 |             int minvalue = IINF, minsoeji;
      |                                  ^~~~~~~~

ソースコード

diff #

//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
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<planet> wakusei(100);
vector<space_station> 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<int> 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;
}
0