結果

問題 No.245 貫け!
ユーザー tkzw_21tkzw_21
提出日時 2015-07-17 23:24:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,094 bytes
コンパイル時間 2,694 ms
コンパイル使用メモリ 156,864 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 18:15:32
合計ジャッジ時間 9,149 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
4,380 KB
testcase_01 AC 42 ms
4,380 KB
testcase_02 AC 41 ms
4,380 KB
testcase_03 AC 31 ms
4,380 KB
testcase_04 AC 43 ms
4,380 KB
testcase_05 AC 53 ms
4,380 KB
testcase_06 AC 64 ms
4,376 KB
testcase_07 AC 26 ms
4,380 KB
testcase_08 AC 152 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 316 ms
4,380 KB
testcase_11 AC 503 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 705 ms
4,376 KB
testcase_16 AC 620 ms
4,380 KB
testcase_17 AC 632 ms
4,380 KB
testcase_18 AC 629 ms
4,384 KB
testcase_19 AC 620 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const double EPS = 1e-8;
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;
	int 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);
		lines.push_back(l);
	}

	vector<pair<int,int>> lp;
	for(int i=-100;i<=100;i++){
		lp.push_back(make_pair(i,-100));
		lp.push_back(make_pair(i,100));
		lp.push_back(make_pair(-100,i));
		lp.push_back(make_pair(100,i));
	}
	int ret =0;
	for(int i=0;i<lp.size();i++){
		for(int j=i+1;j<lp.size();j++){
			int cnt =0;
			P p1(lp[i].first,lp[i].second),p2(lp[j].first,lp[j].second);
			L l(p1,p2);
			for(int k=0;k<n;k++){
				if(intersectSS(l,lines[k])){
					cnt++;
				}
			}
			ret = max(ret,cnt);
		}
	}

	cout << ret << endl;
	return 0;
}
0