結果
問題 | No.245 貫け! |
ユーザー |
![]() |
提出日時 | 2015-07-17 22:36:57 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 38 ms / 5,000 ms |
コード長 | 8,576 bytes |
コンパイル時間 | 837 ms |
コンパイル使用メモリ | 96,980 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-08 08:31:00 |
合計ジャッジ時間 | 1,765 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
#include <cstdio>#include <iostream>#include <vector>#include <map>#include <set>#include <string>#include <cstring>#include <sstream>#include <algorithm>#include <functional>#include <queue>#include <stack>#include <cmath>#include <iomanip>#include <list>#include <tuple>#include <bitset>#include <ciso646>using namespace std;inline bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }template<class T> inline T sqr(T x) { return x*x; }typedef pair<int, int> P;typedef tuple<int, int, int> T;typedef long long ll;typedef unsigned long long ull;#define For(i,a,b) for(int (i) = (a);i < (b);(i)++)#define rep(i,n) For(i,0,n)#define clr(a) memset((a), 0 ,sizeof(a))#define mclr(a) memset((a), -1 ,sizeof(a))#define all(a) (a).begin(),(a).end()#define sz(a) (sizeof(a))#define Fill(a,v) fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)const int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };const int mod = 1000000007;const int INF = 1e9;//--------------------------------------//------------幾何ライブラリ------------//--------------------------------------//--------------------------------------//----------------定義------------------//--------------------------------------#define EPS (1e-10)#define equals(a,b) (fabs((a)-(b)) < EPS)//--------------------------------------//----------------構造体----------------//--------------------------------------//点 ベクトルstruct Point {double x, y;Point(double x = 0, double y = 0){ this->x = x; this->y = y; }Point operator + (Point p){ return Point(x + p.x, y + p.y); }Point operator - (Point p){ return Point(x - p.x, y - p.y); }Point operator * (double k){ return Point(x * k, y * k); }Point operator / (double k){ return Point(x / k, y / k); }double norm(){ return x * x + y * y; }double abs(){ return sqrt(norm()); }double dot(Point a){ return x*a.x + y*a.y; }double cross(Point a){ return x*a.y - y*a.x; }//大小関係の判定 (X座標を優先している)bool operator < (const Point &p) const{ return x != p.x ? x < p.x : y < p.y; }bool operator == (const Point &p) const{ return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS; }};typedef Point Vector;//線分 直線struct Segment{Point p1, p2;Segment(double x1 = 0, double x2 = 0, double y1 = 0, double y2 = 0){p1 = Point(x1, y1); p2 = Point(x2, y2);}Segment(Point p1, Point p2) :p1(p1), p2(p2) {}};typedef Segment Line;//円class Circle{public:Point c;double r;Circle(Point c = Point(), double r = 0.0) :c(c), r(r){}};//多角形typedef vector<Point> Polygon;//--------------------------------------//----------------関数------------------//--------------------------------------//ベクトルのノルムdouble norm(Vector a){return a.x * a.x + a.y * a.y;}//ベクトルの大きさdouble abs(Vector a){return sqrt(norm(a));}//ベクトルの内積double dot(Vector a, Vector b){return a.x * b.x + a.y * b.y;}//ベクトルの外積double cross(Vector a, Vector b){return a.x*b.y - a.y*b.x;}//直行判定 (内積が0であるか) ベクトルa,bの判定bool isOrthogonal(Vector a, Vector b){return equals(dot(a, b), 0.0);}//直行判定 (内積が0であるか) 線分a1-a2,b1-b2 の判定bool isOrthogonal(Point a1, Point a2, Point b1, Point b2){return isOrthogonal(a1 - a2, b1 - b2);}//直行判定 (内積が0であるか) 線分s1,s2の判定bool isOrthogonal(Segment s1, Segment s2){return isOrthogonal(s1.p2, s1.p1, s2.p2, s2.p1);}//平行判定 (外積が0であるか) ベクトルa,bの判定bool isParallel(Vector a, Vector b){return equals(cross(a, b), 0.0);}//平行判定 (外積が0であるか) 線分a1-a2,b1-b2 の判定bool isParallel(Point a1, Point a2, Point b1, Point b2){return isParallel(a1 - a2, b1 - b2);}//平行判定 (外積が0であるか) 線分s1,s2の判定bool isParallel(Segment s1, Segment s2){return isParallel(s1.p2, s1.p1, s2.p2, s2.p1);}//射影Point project(Segment s, Point p){Vector base = s.p2 - s.p1;double r = dot(p - s.p1, base) / norm(base);return s.p1 + base * r;}//反射Point reflect(Segment s, Point p){return p + (project(s, p) - p) * 2.0;}//反時計回り ccw (Counter-Clockwise)static const int COUNTER_CLOCKWISE = 1; //p0,p1,p2が反時計回りstatic const int CLOCKWISE = -1; //p0,p1,p2が時計回りstatic const int ONLINE_BACK = 2; //p2,p0,p1がこの順で同直線上にある場合static const int ONLINE_FRONT = -2; //p0,p1,p2がこの順で同直線上にある場合static const int ON_SEGMENT = 0; //p2が線分p0 p1上にある場合/* COUNTER_CLOCKWISE = 1; //p0,p1,p2が反時計回りCLOCKWISE = -1; //p0,p1,p2が時計回りONLINE_BACK = 2; //p2,p0,p1がこの順で同直線上にある場合ONLINE_FRONT = -2; //p0,p1,p2がこの順で同直線上にある場合ON_SEGMENT = 0; //p2が線分p0 p1上にある場合 */int ccw(Point p0, Point p1, Point p2){Vector a = p1 - p0;Vector b = p2 - p0;if (cross(a, b) > EPS) return COUNTER_CLOCKWISE;if (cross(a, b) < -EPS) return CLOCKWISE;if (dot(a, b) < -EPS) return ONLINE_BACK;if (a.norm() < b.norm()) return ONLINE_FRONT;return ON_SEGMENT;}//交差判定 (線分p1p2 と 線分p3p4の交差判定)bool intersect(Point p1, Point p2, Point p3, Point p4){return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0);}//交差判定 (線分s1と線分s2の交差判定)bool intersect(Segment s1, Segment s2){return intersect(s1.p1, s1.p2, s2.p1, s2.p2);}//交点取得 (線分s1,s2の交点)Point getCrossPoint(Segment s1, Segment s2){Vector base = s2.p2 - s2.p1;double d1 = abs(cross(base, s1.p1 - s2.p1));double d2 = abs(cross(base, s1.p2 - s2.p1));double t = d1 / (d1 + d2);return s1.p1 + (s1.p2 - s1.p1) * t;}//交点取得 (円cと線分lの交点)pair<Point, Point> getCrossPoints(Circle c, Line l){Vector pr = project(l, c.c);Vector e = (l.p2 - l.p1) / abs(l.p2 - l.p1);double base = sqrt(c.r * c.r - norm(pr - c.c));return make_pair(pr + e * base, pr - e * base);}//ベクトルpとx軸がなす角度を求めるdouble arg(Vector p){ return atan2(p.y, p.x); };//大きさa 角度rのベクトルを返すVector polar(double a, double r){ return Point(cos(r) * a, sin(r) * a); }//交点取得 (円c1と円c2の交点)pair<Point, Point> getCrossPoints(Circle c1, Circle c2){double d = abs(c1.c - c2.c);double a = acos((c1.r * c1.r + d*d - c2.r * c2.r) / (2 * c1.r * d));double t = arg(c2.c - c1.c);return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));}/*点の内包点pが多角形gに内包されているかどうかを求めるIN 2 (含まれる)ON 1 (辺上)OUT 0 (含まれない)*/int contains(Polygon g, Point p){int n = g.size();bool x = false;for (int i = 0; i < n; i++){Point a = g[i] - p, b = g[(i + 1) % n] - p;if (abs(cross(a, b)) < EPS && dot(a, b) < EPS)return 1;if (a.y > b.y) swap(a, b);if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)x = !x;}return (x ? 2 : 0);}//距離の取得double getDistance(Point a, Point b){return abs(a - b);}//距離の取得double getDistanceLP(Line l, Point p){return abs(cross(l.p2 - l.p1, p - l.p1)) / abs(l.p2 - l.p1);}//距離の取得double getDistanceSP(Segment s, Point p){if (dot(s.p2 - s.p1, p - s.p1) < 0.0)return abs(p - s.p1);if (dot(s.p1 - s.p2, p - s.p2) < 0.0)return abs(p - s.p2);return getDistanceLP(s, p);}//距離の取得double getDistance(Segment s1, Segment s2){if (intersect(s1, s2))return 0.0;return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)),min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));}int main(){int n;cin >> n;vector<Line> vl;rep(i, n){int a, b, c, d;cin >> a >> b >> c >> d;vl.push_back(Line(Point(a, b), Point(c, d)));}int ans = 0;rep(i, n)rep(j, n){Line tl[4];tl[0] = Line(Point(vl[i].p1), Point(vl[j].p1));tl[1] = Line(Point(vl[i].p1), Point(vl[j].p2));tl[2] = Line(Point(vl[i].p2), Point(vl[j].p1));tl[3] = Line(Point(vl[i].p2), Point(vl[j].p2));rep(k, 4){int tmp = 0;rep(l, n){if(intersect(tl[k],vl[l]))tmp++;}ans = max(tmp, ans);}}cout << ans << endl;return 0;}