結果

問題 No.245 貫け!
ユーザー JohnNakazawaJohnNakazawa
提出日時 2015-07-17 23:36:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 224 ms / 5,000 ms
コード長 3,554 bytes
コンパイル時間 1,179 ms
コンパイル使用メモリ 150,988 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 18:22:13
合計ジャッジ時間 4,008 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define REP(i, init, N) for (int i = (init); i < (int)(N); i++)

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const double EPS = 1e-12;
//const double PI = acos(-1.0);

double add(double a, double b) {
    return ( abs(a + b) < EPS * (abs(a) + abs(b)) ) ? 0 : (a + b);
}

bool eq(double a, double b) {
    return abs(a - b) < EPS;
}

struct P {
	double x, y;
	P() {};
	P(double x_, double y_) : x(x_), y(y_) {}

	P operator + (P p) {
		return P(add(x, p.x), add(y, p.y));
	}

	P operator - (P p) {
		return P(add(x, -p.x), add(y, -p.y));
	}

	P operator * (double d) {
		return P(x * d, y * d);
	}

	P operator / (double d) {
		return P(x / d, y / d);
	}

    bool eq(P p) {
        return ::eq(x, p.x) && ::eq(y, p.y);
    }

	// 内積
	double dot(P p) {
		return add(x * p.x, y * p.y);
	}

	// 外積
	double det(P p) {
		return add(x * p.y, -y * p.x);
	}
};

// 線分上に点があるか
bool on_seg(P p1, P p2, P q) {
	return (p1 - q).det(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0;
}

// 直線と直線の交点
P intersection(P p1, P p2, P q1, P q2) {
	return p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / (q2 - q1).det(p2 - p1));
}

bool linestrx(vector<P> &ps) {
    rep(i, ps.size()) {
        if (!eq(ps[i].x, ps[(i + 1) % (int)ps.size()].x)) {
            return false;
        }
    }
    return true;
}

bool linestry(vector<P> &ps) {
    rep(i, ps.size()) {
        if (!eq(ps[i].y, ps[(i + 1) % (int)ps.size()].y)) {
            return false;
        }
    }
    return true;
}

bool linestr(P p1, P p2, P q1, P q2) {
    vector<P> ps = {p1, p2, q1, q2};
    return linestrx(ps) || linestry(ps);
}

// 直線pと線分qが重なっているか
bool is_cross(P p1, P p2, P q1, P q2) {
    if (linestr(p1, p2, q1, q2)) return true;
    P a = intersection(p1, p2, q1, q2);
    return on_seg(q1, q2, a);
}

typedef pair<P, P> Line;

int main(void) {
    int N;
    cin >> N;
    vector<Line> ls(N);
    for (auto &l : ls) {
        cin >> l.fst.x >> l.fst.y >> l.snd.x >> l.snd.y;
    }

    int res = 1;

    rep(i, N) rep(j, N) {
        rep(p, 2) rep(q, 2) {
            Line l;
            l.fst = p ? ls[i].fst : ls[i].snd;
            l.snd = q ? ls[j].fst : ls[j].snd;

            int cnt = 0;
            rep(k, N) {
                cnt += is_cross(l.fst, l.snd, ls[k].fst, ls[k].snd);
            }

//            cout << cnt << endl;

            res = max(res, cnt);
        }
    }

    cout << res << endl;

	return 0;
}
0