#include <iostream>
#include <cmath>
#include <algorithm>
double const MAX = 99999;
using namespace std;
struct seg{
double k;
double b;
double leftx;
double downy;
double rightx;
double upy;
}l[10001];
void swap(double& a, double& b) {
double tmp = a;
a = b;
b = tmp;
}
bool equal(double a, double b) {
return fabs(a-b) < 1e-6;
}
bool comseg(const seg& a, const seg& b) {
if(equal(a.k, b.k)) {
if(a.k == MAX) {
if(equal(a.b, b.b)) {
if(equal(a.downy, b.upy)) {
return a.upy < b.upy;
}
return a.downy < b.downy;
}
return a.b < b.b;
}
else if(equal(a.b, b.b)) {
if(equal(a.leftx, b.leftx)) {
return a.rightx < b.rightx;
}
return a.leftx < b.leftx;
}
return a.b < b.b;
}
return a.k < b.k;
}
int main() {
int n;
while(cin >> n && n != 0) {
for(int i = 0; i < n; i++) {
cin >> l[i].leftx >> l[i].downy >> l[i].rightx >> l[i].upy;
if(l[i].leftx == l[i].rightx) {
l[i].k = MAX;
l[i].b = l[i].leftx;
if(l[i].downy > l[i].upy) {
swap(l[i].downy, l[i].upy);
}
}
else if(l[i].leftx > l[i].rightx) {
l[i].k = (l[i].upy - l[i].downy) / (l[i].rightx - l[i].leftx);
l[i].b = l[i].downy - l[i].leftx * l[i].k;
swap(l[i].leftx, l[i].rightx);
swap(l[i].downy, l[i].upy);
}
else {
l[i].k = (l[i].upy - l[i].downy) / (l[i].rightx - l[i].leftx);
l[i].b = l[i].downy - l[i].leftx * l[i].k;
}
}
sort(l, l+n, comseg);
int count = 1;
double x = l[0].rightx;
double y = l[0].upy;
for(int i = 1; i < n; i++) {
if(!(equal(l[i].k, l[i-1].k) && equal(l[i].b, l[i-1].b))){
count++;
}
else if(l[i].k == MAX && l[i].downy > y || l[i].k != MAX && l[i].leftx > x) {
count++;
}
else if(l[i].k == MAX && y > l[i].upy || l[i].k != MAX && x >= l[i].rightx) {
continue;
}
x = l[i].rightx;
y = l[i].upy;
}
cout << count << endl;
}
return 0;
}
1004. I Conduit!
最新推荐文章于 2024-09-02 20:37:18 发布