QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#112635#4418. Laser AlarmToboAC ✓926ms3596kbC++202.5kb2023-06-12 16:56:182023-06-12 16:56:20

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-12 16:56:20]
  • 评测
  • 测评结果:AC
  • 用时:926ms
  • 内存:3596kb
  • [2023-06-12 16:56:18]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
#define double long double
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
 
const double eps = 1e-9;
const int N = 510;
 
struct dot{
    double x, y, z;
    dot(double xx = 0, double yy = 0, double zz =0) : x(xx), y(yy), z(zz){}
};
 
inline void scan(dot &a){cin >> a.x >> a.y >> a.z;}
inline void print(dot &a){cout << a.x << a.y << a.z;}
 
struct line{
    dot d, a, b;
    line(dot dd, dot aa, dot bb) : d(dd), a(aa), b(bb){}
};
 
struct plane{
    dot d, a;
    plane(dot dd, dot aa) : d(dd), a(aa){}
};
 
inline dot operator + (const dot &a, const dot &b){return dot(a.x + b.x, a.y + b.y, a.z + b.z);}
inline dot operator - (const dot &a, const dot &b){return dot(a.x - b.x, a.y - b.y, a.z - b.z);}
inline double operator * (const dot &a, const dot &b){return a.x * b.x + a.y * b.y + a.z * b.z;}
inline dot operator ^ (const dot &a, const dot &b)
{
    return dot(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
}
inline double len(const dot &a){return sqrt(a.x * a.x + a.y * a.y + a.z * a.z);}
 
int n;
dot a[N];
 
inline bool inte(const plane &p, const line &l){
    double t1 = (l.a - p.a) * p.d, t2 = (l.b - p.a) * p.d;
    if(abs(t1) < eps || abs(t2) < eps) return true;
    if((t1 > eps) ^ (t2 > eps)) return true;
    return false;
}
 
inline bool coll(const dot &a, const dot &b){
    return abs(len(a ^ b)) < eps;
}
 
void solve(){
    cin >> n;
    for(int i = 1; i <= 2 * n; i ++) scan(a[i]);
    int ans = 0;
    for(int i = 1; i < 2 * n; i ++){
        for(int j = 1; j < i; j ++){
            for(int k = 1; k < j; k++){
                dot t = (a[i] - a[j]) ^ (a[i] - a[k]);
                if(len(t) < eps) continue;
                plane p = plane(t, a[i]);
                int res = 0;
                for(int c = 1; c <= n; c++){
                    line l = line(a[2 * c - 1] - a[2 * c], a[2 * c - 1], a[2 * c]);
                    if(inte(p, l)) res ++;
                }
                ans = max(ans, res);
            }
            int res = 0;
            for(int c = 1; c <= n; c++){
                dot t = a[i] - a[j];
                if(coll(t, a[i] - a[2 * c - 1]) || coll(t, a[i] - a[2 * c])) res ++;
            }
            ans = max(ans, res);
        }
    }
    cout << ans << '\n';
}
 
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 926ms
memory: 3596kb

input:

10
50
94 57 39 12 69 59
86 46 44 17 32 83
35 86 71 47 41 50
68 93 71 54 28 25
92 74 2 30 60 86
87 52 54 32 17 88
51 63 96 23 12 69
1 82 85 20 9 90
25 72 42 49 4 52
30 86 94 93 43 34
10 45 30 85 32 75
84 37 71 37 78 19
28 30 7 40 10 77
5 68 86 83 3 41
71 73 8 86 69 48
65 11 6 49 64 50
61 2 24 60 11 9...

output:

33
39
36
36
40
37
34
33
50
50

result:

ok 10 lines