QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#601107 | #5251. Constellations | hzy99999 | WA | 2330ms | 34980kb | C++20 | 2.3kb | 2024-09-29 20:51:05 | 2024-09-29 20:51:05 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 2e3 + 10;
const double eps = 1e-6;
double dist[N][N];
int n;
PII point[N];
int p[N], sz[N], year[N]; // year越小越老
int dcmp(double a, double b)
{
if (fabs(a - b) < eps)
return 0;
if (a < b)
return -1;
return 1;
}
// int find(int x)
// {
// if (x != p[x])
// p[x] = find(p[x]);
// return p[x];
// }
double get_dist(PII a, PII b)
{
int dx = a.x - b.x, dy = a.y - b.y;
return sqrt(dx * dx + dy * dy);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
sz[i] = 1; // p[i] = i;
for (int i = 1; i <= n; i++)
{
int x, y;
cin >> x >> y;
point[i] = {x, y};
year[i] = i;
}
int stand = n;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
dist[i][j] = dist[j][i] = get_dist(point[i], point[j]);
vector<int> num;
for (int i = 1; i <= n; i++)
num.push_back(i);
for (int k = 1; k < n; k++)
{
PII t = {-1, -1}; // 存位置
double minv = 1e18;
for (int i = 0; i < num.size(); i++)
for (int j = i + 1; j < num.size(); j++)
{
int a = num[i], b = num[j];
if (year[a] < year[b])
swap(a, b);
if (t.x == -1 || dcmp(minv, dist[a][b]) > 0 || dcmp(minv, dist[a][b]) == 0 && (year[t.x] > year[a] || year[t.x] == year[a] && year[t.y] < year[b]))
t = {i, j}, minv = dist[a][b];
}
for (int i = 0; i < num.size(); i++)
{
if (i == t.x || i == t.y)
continue;
int x = num[t.x], y = num[t.y];
int a = num[i];
dist[x][a] = dist[a][x] = (dist[x][a] * sz[x] + dist[y][a] * sz[y]) / (sz[x] + sz[y]);
}
sz[num[t.x]] += sz[num[t.y]];
year[num[t.x]] = ++stand;
cout << sz[num[t.x]] << endl;
num.erase(num.begin() + t.y);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
2 0 0 1 0
output:
2
result:
ok single line: '2'
Test #2:
score: -100
Wrong Answer
time: 2330ms
memory: 34980kb
input:
2000 1000 -1000 1000 -999 1000 -998 1000 -997 1000 -996 1000 -995 1000 -994 1000 -993 1000 -992 1000 -991 1000 -990 1000 -989 1000 -988 1000 -987 1000 -986 1000 -985 1000 -984 1000 -983 1000 -982 1000 -981 1000 -980 1000 -979 1000 -978 1000 -977 1000 -976 1000 -975 1000 -974 1000 -973 1000 -972 1000...
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
wrong answer 765th lines differ - expected: '2', found: '3'