結果

問題 No.245 貫け!
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-31 05:36:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,537 bytes
コンパイル時間 1,071 ms
コンパイル使用メモリ 107,224 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-17 08:49:51
合計ジャッジ時間 1,804 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 10 ms
4,376 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 11 ms
4,376 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 11 ms
4,380 KB
testcase_17 AC 11 ms
4,376 KB
testcase_18 AC 10 ms
4,380 KB
testcase_19 AC 10 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <sstream>

using namespace std;

template <typename T>
struct point{
    T x, y;
};

//judge if line AB intersects line CD
template <typename T>
bool intersect(point<T> &a, point<T> &b, point<T> &c, point<T> &d){
    bool ans = 1;
    T s, t;
    s = (a.x - b.x) * (c.y - a.y) - (a.y - b.y) * (c.x - a.x);
    t = (a.x - b.x) * (d.y - a.y) - (a.y - b.y) * (d.x - a.x);
    if (s*t > 0) ans = 0;
    s = (c.x - d.x) * (a.y - c.y) - (c.y - d.y) * (a.x - c.x);
    t = (c.x - d.x) * (b.y - c.y) - (c.y - d.y) * (b.x - c.x);
    if (s*t > 0) ans = 0;
    return ans;
}

int main(){

    long long N, mx=0, M, cnt, dx, dy;
    cin >> N;
    point<long long> e1, e2;
    vector<point<long long>> c(N), d(N), e(2*N);
    for (int i=0; i<N; i++){
        cin >> c[i].x >> c[i].y >> d[i].x >> d[i].y;
        e[i*2] = c[i]; e[i*2+1] = d[i];
    }

    for (int i=0; i<N*2; i++){
        for (int j=i+1; j<N*2; j++){
            cnt = 0;
            dx = e[i].x - e[j].x;
            dy = e[i].y - e[j].y;
            e1.x = e[i].x + 1000 * dx;
            e1.y = e[i].y + 1000 * dy;
            e2.x = e[i].x - 1000 * dx;
            e2.y = e[i].y - 1000 * dy;
            for (int k=0; k<N; k++){
                if (intersect(e1, e2, c[k], d[k])) cnt++;
            }
            mx = max(mx, cnt);
        }
    }

    cout << mx << endl;

    return 0;
}
0