結果

問題 No.245 貫け!
ユーザー omu
提出日時 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
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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; //p2p0 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; //p2p0 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);
}
// (s1s2)
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;
}
// (cl)
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);
}
//px
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); }
// (c1c2)
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));
}
/*
pg
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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0