Pages

Thursday, September 17, 2015

Division of Nlogonia (KICTM UiTM Jasin 2015)



After centuries of hostilities and skirmishes between the four nations living in the land generally known as Nlogonia, and years of negotiations involving diplomats, politicians and the armed forces of all interested parties, with mediation by UN, NATO, G7 and SBC, it was at last agreed by all the way to end the dispute, dividing the land into four independent territories.

It was agreed that one point, called division point, with coordinates established in the negotiations, would define the country division, in the following way. Two lines, both containing the division point, one in the North-South direction and one in the East-West direction, would be drawn on the map, dividing the land into four new countries. Starting from the Western-most, Northern-most quadrant, in clockwise direction, the new countries will be called Northwestern Nlogonia, Northeastern Nlogonia, Southeastern Nlogonia and Southwestern Nlogonia.



The UN determined that a page in the Internet should exist so that the inhabitants could check in which of the countries their homes are. You have been hired to help implementing the system.

Input
The input contains several test cases. The first line of a test case contains one integer K indicating the number of queries that will be made (0 < K ≤ 103). The second line of a test case contains two integers N and M representing the coordinates of the division point (-104 < N, M < 104). Each of the K following lines contains two integers X and Y representing the coordinates of a residence (-104 ≤ X, Y ≤ 104).

The end of input is indicated by a line containing only the number zero.

Output

For each test case in the input your program must print one line containing:

  • the word divisa (means border in Portuguese) if the residence is on one of the border lines (North-South or East-West);
  • NO (means NW in Portuguese) if the residence is in Northwestern Nlogonia;
  • NE if the residence is in Northeastern Nlogonia;
  • SE if the residence is in Southeastern Nlogonia;
  • SO (means SW in Portuguese) if the residence is in Southwestern Nlogonia.

Sample Input
3
2 1
10 10
-10 1
0 33
4
-1000 -1000
-1000 -1000
0 0
-2000 -10000
-999 -1001
0

Sample Output
NE
divisa
NO
divisa
NE
SO
SE

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.*;
import java.lang.*;
import java.math.*;

public class Q7{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String line = System.getProperty("line.separator");
      scan.useDelimiter(line);
  
      while(true){         
         int cases = scan.nextInt(); 
         if(cases == 0)
            break;
          
         String[] coor = scan.next().split(" ");
         int coorx = Integer.parseInt(coor[0]);
         int coory = Integer.parseInt(coor[1]);
         
         String[] input = new String[cases];
         for(int x=0;x<cases;x++){
            input[x] = scan.next();
               
            String[] get = input[x].split(" ");
            
            int getx = Integer.parseInt(get[0]);
            int gety = Integer.parseInt(get[1]);
            
            int totalx = getx-coorx;
            int totaly = gety-coory;
                        
            if(totalx == 0 || totaly == 0)
               System.out.println("divisa");
            else if(totalx >0 && totaly >0)
               System.out.println("NE");
            else if(totalx <0 && totaly >0)
               System.out.println("NO");
            else if(totalx <0 && totaly <0)
               System.out.println("SO");
            else if(totalx >0 && totaly <0)
               System.out.println("SE");
         }
      }
   }
}

No comments:

Post a Comment