結果
| 問題 | 
                            No.245 貫け!
                             | 
                    
| コンテスト | |
| ユーザー | 
                             maine_honzuki
                         | 
                    
| 提出日時 | 2021-05-03 16:28:18 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 32 ms / 5,000 ms | 
| コード長 | 1,403 bytes | 
| コンパイル時間 | 1,845 ms | 
| コンパイル使用メモリ | 200,024 KB | 
| 最終ジャッジ日時 | 2025-01-21 06:17:17 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 16 | 
ソースコード
//https://ncode.syosetu.com/n4830bu/245/
#include <bits/stdc++.h>
using namespace std;
using Real = double;
using Point = complex<Real>;
#define x real()
#define y imag()
const Real EPS = 1e-8, PI = acos(-1);
Real cross(const Point& a, const Point& b) {
    return a.x * b.y - a.y * b.x;
}
struct Line {
    Point a, b;
    Line(Point a, Point b) : a(a), b(b) {}
};
struct Segment : Line {
    Segment(Point a, Point b) : Line(a, b) {}
};
bool intersect(const Line& l, const Segment& s) {
    return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS;
}
int main() {
    int N;
    cin >> N;
    vector<Segment> segments;
    for (int i = 0; i < N; i++) {
        Real a, b, c, d;
        cin >> a >> b >> c >> d;
        segments.push_back({{a, b}, {c, d}});
    }
    vector<Line> lines;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < i; j++) {
            lines.push_back({segments[i].a, segments[j].a});
            lines.push_back({segments[i].a, segments[j].b});
            lines.push_back({segments[i].b, segments[j].a});
            lines.push_back({segments[i].b, segments[j].b});
        }
    }
    int ans = 1;
    for (auto&& l : lines) {
        if (l.a == l.b)
            continue;
        int maine = 0;
        for (auto&& s : segments) {
            maine += intersect(l, s);
        }
        ans = max(ans, maine);
    }
    cout << ans << endl;
}
            
            
            
        
            
maine_honzuki