結果
| 問題 | 
                            No.245 貫け!
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tkzw_21
                         | 
                    
| 提出日時 | 2015-07-18 13:45:38 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 12 ms / 5,000 ms | 
| コード長 | 2,050 bytes | 
| コンパイル時間 | 1,526 ms | 
| コンパイル使用メモリ | 168,176 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-08 10:10:00 | 
| 合計ジャッジ時間 | 1,954 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 16 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-6;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
typedef vector<P> G;
struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};
bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
int main(void){
    int n;
    cin >> n;
    vector<L> lines;
    vector<P> pts;
    double a,b,c,d;
    for(int i=0;i<n;i++){
        cin >> a >>  b >> c >> d;
        P p1(a,b),p2(c,d);
        L l(p1,p2);
        pts.push_back(p1);
        pts.push_back(p2);
        lines.push_back(l);
    }
    int ret = 0;
    for(int i=0;i<pts.size();i++){
    	for(int j=i+1;j<pts.size();j++){
    		if(pts[i] == pts[j])continue;
    		L l2(pts[i],pts[j]);
    		int cnt = 0;
    		for(int k=0;k<n;k++){
	    		if(intersectLS(l2,lines[k])){
	    			cnt++;
	    		}
    		}
    		ret = max(ret,cnt);
    	}
    }
    
    cout << ret << endl;
    return 0;
}
            
            
            
        
            
tkzw_21