import java.beans.beancontext.BeanContext;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
public class Main{
public static void main(String[] args) throws IOException{
InputReader in = new InputReader(System.in) ;
StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out = new PrintWriter(System.out);
int n ;
while((n = in.nextInt()) != 0){
new Task().solve(n , in , out) ;
out.flush() ;
}
out.flush() ;
}
}
class Task{
P[] p , q ;
int n ;
boolean[][] dp ;
public Task(){
}
public void solve(int n , InputReader in , PrintWriter out){
this.n = n ;
dp = new boolean[n][n] ;
p = new P[n] ;
q = new P[n] ;
for(int i = 0 ; i < n ; i++){
p[i] = new P(in.nextDouble(), in.nextDouble()) ;
q[i] = new P(in.nextDouble(), in.nextDouble()) ;
}
for(int i = 0 ; i < n ; i++){
dp[i][i] = true ;
for(int j = 0 ; j < i ; j++){
if(p[i].sub(q[i]).det(p[j].sub(q[j])) == 0){
dp[i][j] = dp[j][i] = p[j].on_seg(p[i], q[i]) ||
q[j].on_seg(p[i], q[i]) ||
p[i].on_seg(p[j], q[j]) ||
q[i].on_seg(p[j], q[j]) ;
}
else{
P r = P.intersection(p[i], q[i], p[j], q[j]) ;
dp[i][j] = dp[j][i] = r.on_seg(p[i], q[i]) && r.on_seg(p[j], q[j]) ;
}
}
}
for(int k = 0 ; k < n ; k++){
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < n ; j++){
dp[i][j] |= dp[i][k] && dp[k][j] ;
}
}
}
for(;;){
int u = in.nextInt() , v = in.nextInt() ;
if(u == 0 && v == 0) break ;
if(dp[u-1][v-1]) out.println("CONNECTED") ;
else out.println("NOT CONNECTED") ;
}
}
}
class P{
double EPS = 1e-10 ;
double x , y ;
public double add(double a , double b){
if(Math.abs(a+b) < EPS * (Math.abs(a) + Math.abs(b))) return 0 ;
return a + b ;
}
public P(){
}
public P(double x , double y){
this.x = x ;
this.y = y ;
}
public P add(P o){
return new P(add(x , o.x) , add(y , o.y) ) ;
}
public P sub(P o){
return new P(add(x , -o.x) , add(y , -o.y) ) ;
}
public P mult(double d){
return new P(x * d , y * d) ;
}
public double dot(P o){
return add(x*o.x , y*o.y) ;
}
public double det(P o){
return add(x*o.y , -y*o.x) ;
}
public boolean on_seg(P p1 , P p2){
return p1.sub(this).det(p2.sub(this)) == 0 &&
p1.sub(this).dot(p2.sub(this)) <= 0 ;
}
public static P intersection(P p1 , P p2 , P q1 , P q2){
return p1.add( p2.sub(p1).mult(
q2.sub(q1).det(q1.sub(p1)) / q2.sub(q1).det(p2.sub(p1))
) );
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
POJ1127几何
最新推荐文章于 2019-02-19 16:23:25 发布