QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#386478#5809. Min Perimeterdebgxh5 319ms29240kbC++141.5kb2024-04-11 17:15:182024-04-11 17:15:20

Judging History

你现在查看的是最新测评结果

  • [2024-04-11 17:15:20]
  • 评测
  • 测评结果:5
  • 用时:319ms
  • 内存:29240kb
  • [2024-04-11 17:15:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 1000005;
int n, T; pair<double, double> A[MAXN]; vector<int> To[MAXN];
double Ans = INFINITY, Lim = INFINITY;
double dis(int i, int j){return hypot(A[i].first - A[j].first, A[i].second - A[j].second);}
int main(){
  cin.tie(nullptr)->sync_with_stdio(false);
  mt19937 rnd(time(nullptr));
  cin >> T; for(int t = 1; t <= T; t++){
    cin >> n; double alpha = (double)rnd() / UINT32_MAX * acos(-1);
    Ans = Lim = INFINITY;
    for(int i = 1; i <= n; i++){
      int x, y; cin >> x >> y, alpha = 0;
      A[i].first  = x * cos(alpha) - y * sin(alpha);
      A[i].second = y * cos(alpha) + x * sin(alpha);
      To[i].clear();
    }
    sort(A + 1, A + n + 1);
    for(int i = 1; i <= n; i++){
      double mn = INFINITY, se = INFINITY;
      for(int j = -100; j <= 100; j++) if(j && 1 <= i + j && i + j <= n){
        double len = dis(i, i + j);
        if(len < mn) se = mn, mn = len; else se = min(se, len);
      }
      Lim = min(Lim, mn + se);
    }
    for(int i = 1; i <= n; i++)
      for(int j = 1; j <= 100 && i + j <= n; j++) if(dis(i, i + j) < Lim * 1.1 + 0.1)
        To[i].push_back(i + j), To[i + j].push_back(i);
    for(int i = 1; i <= n; i++) for(auto j: To[i]) for(auto k: To[j]) for(auto t: To[k])
      if(t == i){Ans = min(Ans, dis(i, j) + dis(j, k) + dis(k, i)); break;}
    cout << "Case #" << t << ": " << fixed << setprecision(14) << Ans << '\n';
  }
  cerr << (double)clock() / CLOCKS_PER_SEC << endl;
  return 0;
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 319ms
memory: 29240kb

input:

15
3
2 6
7 0
3 0
3
713 269
371 79
455 421
3
91983245 637281504
756917015 312173515
869576338 436726680
10000
14761642 78236002
9047458 47951098
5238002 27761162
476182 2523742
1428546 7571226
26190010 138805810
21904372 116092132
18094916 95902196
43332562 229660522
55237112 292754072
52380020 27761...

output:

Case #1: 17.89301220620487
Case #2: 1042.84483496438816
Case #3: 1711142102.79132699966431
Case #4: 90912.29637403292872
Case #5: 3.41421356237309
Case #6: 26.15383034216369
Case #7: 1701.01268109561670
Case #8: 2865438.19199387123808
Case #9: 2020088.33722631959245
Case #10: 1792106.03729207115248
...

result:

ok correct! (15 test cases)

Subtask #2:

score: 0
Time Limit Exceeded

Test #2:

score: 0
Time Limit Exceeded

input:

15
3
501691275 344354353
167768963 536043860
249445040 557426549
4
1000000000 0
0 0
1000000000 1000000000
0 1000000000
1000000
138925776 669369648
61257680 295150640
170762328 822763944
55483472 267329456
97736936 470914328
84041848 404928904
18463588 88960924
124429360 599523280
95066048 458045504
...

output:


result: