QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#192696#7521. Find the Gapucup-team896#WA 3ms3796kbC++143.3kb2023-09-30 15:17:232023-09-30 15:17:23

Judging History

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

  • [2023-09-30 15:17:23]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3796kb
  • [2023-09-30 15:17:23]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ " = "), debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

using namespace std;

const int N = 55;

struct coor
{
    int x,y,z;//坐标,也可以表示成向量,向量也是一个坐标表示嘛
    coor(){}
    coor(int xx,int yy,int zz):x(xx),y(yy),z(zz){}
    bool operator &(coor a) const //判断两个向量是否共线,共线返回true
    {
        //思路:判断叉积,是否各项系数都是0
        return (y*a.z - z*a.y)==0 && (z*a.x - x*a.z)==0 && (x*a.y - y*a.x)==0;
    }
    coor operator ^(coor a) const //得到两个向量的叉积(就是向量积),返回的是一个向量(坐标)
    {
        return coor(y*a.z - z*a.y,z*a.x - x*a.z,x*a.y - y*a.x);
    }
    coor operator -(coor a) const //如果是c-d的话,得到向量dc,
    {
        return coor(x-a.x,y-a.y,z-a.z);
    }
    int operator *(coor a) const //得到两个向量的 数量积,返回整数即可
    {
        return x*a.x+y*a.y+z*a.z;
    }
}zb[N];

bool all_in_Aline(int n)
{
    //思路,暴力枚举,每三个点,看看是不是所有叉积都是0
    for (int i=1;i<=n;++i) //这个作为起点吧
        for (int j=i+1;j<=n;++j)
            for (int k=j+1;k<=n;++k)
            {
                coor t1 = zb[k]-zb[i];
                coor t2 = zb[j]-zb[i];
                if (t1&t2) continue;
                return false;
            }
    return true;
}

bool checkThree (coor a,coor b,coor c)
{
    return (b-a)&(c-a);
}

int n, a[N], b[N], c[N];
mt19937 rnd(random_device{}());

template<class T> double pw(T x) { return 1. * x * x; }
template<class T> int sign(T x) { return x == 0 ? 3 : (x < 0 ? 1 : 2); }

double calc(int x, int y, int z) {
  if (checkThree(zb[x],zb[y],zb[z])) return 1e18;
  coor p1 = zb[x], p2 = zb[y], p3 = zb[z];
  double A = ( (p2.y-p1.y)*(p3.z-p1.z)-(p2.z-p1.z)*(p3.y-p1.y) );
  double B = ( (p2.z-p1.z)*(p3.x-p1.x)-(p2.x-p1.x)*(p3.z-p1.z) );
  double C = ( (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x) );
  double D = ( 0-(A*p1.x+B*p1.y+C*p1.z) );
  int And = 3;
  double mx = 0, ss = sqrt(pw(A) + pw(B) + pw(C));
  rep (i, 1, n) {
    And &= sign(A * a[i] + B * b[i] + C * c[i] + D);
    mx = max(mx, abs(A * a[i] + B * b[i] + C * c[i] + D) / ss);
  }
  return And ? mx : 1e18;
}

int main() {
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin >> n;
  rep (i, 1, n) cin >> a[i] >> b[i] >> c[i];
  if (n == 1) return cout << double(0), 0;
  if (n == 2) return cout << sqrt(pw(a[1] - a[2]) + pw(b[1] - b[2]) + pw(c[1] - c[2])), 0;
  rep (i, 1, n) zb[i] = (coor){a[i], b[i], c[i]};
  if (all_in_Aline(n)) return cout << double(0), 0;
  double ans = 1e18;
  rep (i, 1, n) rep (j, i + 1, n) rep (k, j + 1, n) ans = min(ans, calc(i, j, k));
  cout << (ans > 1e17 ? 0. : ans) << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3552kb

input:

8
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
2 2 2

output:

1.0000000000

result:

ok found '1.000000000', expected '1.000000000', error '0.000000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

5
1 1 1
1 2 1
1 1 2
1 2 2
2 1 1

output:

0.7071067812

result:

ok found '0.707106781', expected '0.707106781', error '0.000000000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3624kb

input:

50
973 1799 4431
1036 1888 4509
1099 1977 4587
1162 2066 4665
1225 2155 4743
1288 2244 4821
1351 2333 4899
1414 2422 4977
1540 2600 5133
1603 2689 5211
1666 2778 5289
1729 2867 5367
1792 2956 5445
1855 3045 5523
1918 3134 5601
1981 3223 5679
2044 3312 5757
2107 3401 5835
2170 3490 5913
2296 3668 606...

output:

0.0000000000

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

50
4532 3245 1339
4624 3260 1345
4716 3275 1351
4808 3290 1357
4900 3305 1363
5084 3335 1375
5176 3350 1381
5268 3365 1387
5360 3380 1393
5452 3395 1399
5544 3410 1405
5728 3440 1417
5820 3455 1423
5912 3470 1429
6096 3500 1441
6188 3515 1447
6280 3530 1453
6372 3545 1459
6464 3560 1465
6556 3575 14...

output:

0.0000000000

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #5:

score: 0
Accepted
time: 3ms
memory: 3796kb

input:

50
1 70 7443
1 138 5063
2 109 5971
3 23 8874
3 152 4359
4 59 7507
5 50 7715
5 73 6910
7 25 8376
7 103 5646
8 3 9039
9 83 6132
9 142 4067
10 124 4590
11 140 3923
12 168 2836
13 46 6999
13 84 5669
13 189 1994
13 229 594
15 171 2410
16 94 4998
20 38 6530
20 125 3485
21 78 5023
22 210 296
23 117 3444
25...

output:

0.0000000000

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3796kb

input:

50
1 95 5991
3 22 9019
25 103 5199
25 141 3603
38 103 4952
39 139 3421
59 6 8627
60 48 6844
66 33 7360
107 88 4271
109 188 33
112 177 438
114 107 3340
122 77 4448
123 169 565
127 1 7545
142 161 540
143 70 4343
146 153 800
156 129 1618
162 63 4276
162 150 622
166 93 2940
173 78 3437
180 143 574
189 1...

output:

0.0000000000

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #7:

score: -100
Wrong Answer
time: 3ms
memory: 3796kb

input:

50
14 3658 1218
17 32 7984
741 1906 5773
755 8668 1019
834 2386 4591
1306 3866 7044
2304 2895 120
2450 8613 7374
2595 1919 2119
2610 9866 9419
2694 2845 2941
2838 2702 7608
2883 4143 4049
3082 4800 3611
3338 6703 9039
3424 2035 1863
3471 2672 5858
4339 1330 2029
4720 6970 4719
4853 387 5866
5415 975...

output:

9414.0579641642

result:

wrong answer 1st numbers differ - expected: '9341.5658962', found: '9414.0579642', error = '0.0077602'