結果
| 問題 |
No.245 貫け!
|
| コンテスト | |
| ユーザー |
JohnNakazawa
|
| 提出日時 | 2015-07-17 23:36:11 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 201 ms / 5,000 ms |
| コード長 | 3,554 bytes |
| コンパイル時間 | 1,300 ms |
| コンパイル使用メモリ | 164,696 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-08 09:37:52 |
| 合計ジャッジ時間 | 3,696 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#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;
}
JohnNakazawa