/* check if line ab intersectes with segment cd*/ int check(pt_t a, pt_t b, pt_t c, pt_t d) { double tx, ty; intersec(a, b, c, d, &tx, &ty); if(online(a, b, c, d)) return 0; if(onpara(a, b, c, d)) return 0; if(dcmp(ty - d.y) >= 0 && dcmp(c.y - ty) >= 0) return 1; return 0; }
void solve() { double maxx, tx, ty; int flag, i, j, k; pt_t a, b; maxx = upper[1].x; for(i = 1;i <= n; i++) { for(j = 1;j <= n; j++) { flag = 0; if(i == j) continue; a.x = upper[i].x; a.y = upper[i].y; b.x = botto[j].x; b.y = botto[j].y; for(k = (i > j ? i : j);k >= 1; k--) { if(check(a, b, upper[k], botto[k]) == 0) break; } if(k >= 1) continue; for(k = 1;k <= n; k++) { if(check(a, b, upper[k], botto[k]) == 0) break; } if(k > n) { flag = 1; break;} intersec(a, b, upper[k-1], upper[k], &tx, &ty); if(dcmp(tx - upper[k-1].x) >= 0 && dcmp(upper[k].x - tx) >= 0) { if(maxx + eps < tx) maxx = tx; } intersec(a, b, botto[k-1], botto[k], &tx, &ty); if(dcmp(tx - botto[k-1].x) >= 0 && dcmp(botto[k].x - tx) >= 0) { if(maxx + eps < tx) maxx = tx; } } if(flag) break; } if(flag) printf("Through all the pipe.\n"); else printf("%0.2lf\n", maxx); }
int main() { int a[100], b[100], c[100], i, j, n; printf("qual o numero de conjuntos? "); scanf("%d", &n); lerVetor(a); for (i = 1; i < n; i++) { lerVetor(b); intersec(a, b, c); memcpy(&a, &c, sizeof a); } printf("\na interseccao dos conjuntos é "); imprimirVetor(c); return 0; }