結果

問題 No.245 貫け!
ユーザー airis
提出日時 2015-07-20 15:26:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 3,195 bytes
コンパイル時間 809 ms
コンパイル使用メモリ 83,040 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 11:15:18
合計ジャッジ時間 1,466 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <numeric>
#include <bitset>
#include <complex>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++)
#define EPS (1e-8)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;
struct P {
double x, y;
P() : x(0), y(0) {}
P(double x, double y) : x(x), y(y) {};
double add(double a, double b) { //
if (abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
return a + b;
}
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);
}
double dot(P p) { //
return add(x * p.x, y * p.y);
}
double cross(P p) { //
return add(x * p.y, -y * p.x);
}
};
bool intersect(P s1, P e1, P s2, P e2) { //
//x
//if (max(s1.x, e1.x) < min(s2.x, e2.x) || max(s2.x, e2.x) < min(s1.x, e1.x)) return false;
//y
//if (max(s1.y, e1.y) < min(s2.y, e2.y) || max(s2.y, e2.y) < min(s1.y, e1.y)) return false;
//
double res1 = (e1 - s1).cross(s2 - s1) * (e1 - s1).cross(e2 - s1);
//double res2 = (e2 - s2).cross(e1 - s2) * (e2 - s2).cross(s1 - s2);
//return (res1 < EPS) && (res2 < EPS);
return res1 < EPS; //
}
bool on_seg(P p1, P p2, P q) { // p1-p2q
return (p1 - q).cross(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0;
}
int N;
P s[105], e[105];
P v[210];
int ans;
int calc(P p, P q) {
int res = 0;
rep(i, N) {
bool x = intersect(p, q, s[i], e[i]);
res += x;
//if (p.x == -39 && p.y == -35 && q.x == 39 && q.y == 81) {
// printf("%2d: %c (%f,%f) (%f,%f)\n", i, x > 0 ? 'o' : 'x', s[i].x, s[i].y, e[i].x, e[i].y);
//}
}
//if (p.x == -39 && p.y == -35 && q.x == 39 && q.y == 81) {
// printf("[%d]\n", res);
//}
return res;
}
int main() {
cin >> N;
rep(i, N) {
cin >> s[i].x >> s[i].y >> e[i].x >> e[i].y;
v[2*i] = s[i];
v[2*i+1] = e[i];
}
int mx_i = -1, mx_j = -1;
for (int i = 0; i < 2 * N; i++) {
for (int j = i+1; j < 2 * N; j++) {
if (v[i].x == v[j].x && v[i].y == v[j].y) continue;
int tmp = calc(v[i], v[j]);
if (tmp > ans) {
ans = tmp;
mx_i = i;
mx_j = j;
}
}
}
//printf("(%f, %f) (%f, %f)\n", v[mx_i].x, v[mx_i].y, v[mx_j].x, v[mx_j].y);
//(-39.000000, -35.000000) (39.000000, 81.000000)
//for (int i = 0; i < N; i++) {
// ans = max(ans, calc(s[i], e[i]));
// for (int j = i + 1; j < N; j++) {
// ans = max(ans, calc(s[i], s[j]));
// ans = max(ans, calc(s[i], e[j]));
// ans = max(ans, calc(e[i], s[j]));
// ans = max(ans, calc(e[i], e[j]));
// }
//}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0