Last active
November 1, 2016 13:31
-
-
Save yurahuna/981aba180a5eb4dc7328f35f9a610c53 to your computer and use it in GitHub Desktop.
Area Separation http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2009
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define int long long // <-----!!!!!!!!!!!!!!!!!!! | |
#define rep(i,n) for (int i=0;i<(n);i++) | |
#define rep2(i,a,b) for (int i=(a);i<(b);i++) | |
#define rrep(i,n) for (int i=(n)-1;i>=0;i--) | |
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--) | |
#define all(a) (a).begin(),(a).end() | |
#define rall(a) (a).rbegin(),(a).rend() | |
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl | |
#define printVS(vs) for(auto x : vs){cout << x << endl;} | |
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;} | |
#define printP(p) cout << p.first << " " << p.second << endl | |
#define printVP(vp) for(auto p : vp) printP(p); | |
#define readV(_v) rep(j, _v.size()) cin >> _v[j]; | |
#define readVV(_vv) rep(i, _vv.size()) readV(_vv[i]); | |
#define output(_x) cout << _x << endl; | |
typedef long long ll; | |
typedef pair<int, int> Pii; | |
typedef tuple<int, int, int> TUPLE; | |
typedef vector<int> vi; | |
typedef vector<vi> vvi; | |
typedef vector<vvi> vvvi; | |
typedef vector<Pii> vp; | |
const int inf = 1e9; | |
const int mod = 1e9 + 7; | |
typedef complex<double> P; | |
typedef vector<P> G; | |
#define here(g, i) g[i] | |
#define next(g, i) g[(i + 1) % g.size()] | |
#define prev(g, i) g[(i - 1 + g.size()) % g.size()] | |
const double EPS = 1e-10; | |
const double INF = 1e12; | |
const double PI = acos(-1); | |
struct L { | |
P a, b, v; | |
L(){} | |
L(P _a, P _b) : a(_a), b(_b), v(b - a) {} | |
L(double _ax, double _ay, double _bx, double _by) : L(P(_ax, _ay), P(_bx, _by)) {} | |
}; | |
double cross(P a, P b) { | |
return imag(conj(a) * b); | |
} | |
double dot(P a, P b) { | |
return real(conj(a) * b); | |
} | |
int ccw(P p0, P p1, P p2) { | |
if (cross(p1 - p0, p2 - p0) > 0) return +1; // counter-clockwise | |
if (cross(p1 - p0, p2 - p0) < 0) return -1; // clockwise | |
if (dot(p1 - p0, p2 - p0) < 0) return +2; // online_back | |
if (dot(p0 - p1, p2 - p1) < 0) return -2; // online_front | |
return 0; // on_segment | |
} | |
bool intersectSS(L l1, L l2) { | |
return (ccw(l1.a, l1.b, l2.a) * ccw(l1.a, l1.b, l2.b) < 0 && | |
ccw(l2.a, l2.b, l1.a) * ccw(l2.a, l2.b, l1.b) < 0); | |
} | |
P crosspointSS(L l1, L l2) { | |
double d1 = abs(cross(l2.v, l1.a - l2.a)); | |
double d2 = abs(cross(l2.v, l1.b - l2.a)); | |
double t = d1 / (d1 + d2); | |
return l1.a + t * l1.v; | |
} | |
L readL() { | |
double xa, ya, xb, yb; | |
cin >> xa >> ya >> xb >> yb; | |
return L(xa, ya, xb, yb); | |
} | |
int Count(vector<P> p) { | |
int n = p.size(); | |
int ret = 0; | |
rep(i, n) { | |
bool flag = true; | |
rep(j, i) { | |
if (p[i] == p[j]) { | |
flag = false; | |
break; | |
} | |
} | |
ret += flag; | |
} | |
return ret; | |
} | |
signed main() { | |
std::ios::sync_with_stdio(false); | |
std::cin.tie(0); | |
int n; | |
while (cin >> n, n) { | |
int ans = 1; | |
vector<L> l(n); | |
rep(i, n) { | |
l[i] = readL(); | |
vector<P> p; | |
rep(j, i) { | |
if (intersectSS(l[i], l[j])) { | |
p.emplace_back(crosspointSS(l[i], l[j])); | |
} | |
} | |
ans += Count(p) + 1; | |
} | |
cout << ans << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment