Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1091

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1091

Division of Nlogonia

 

By Ricardo Anido  Brazil

Timelimit: 1

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 (-104X, 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.

 

 

 

Input Sample Output Sample

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

NE
divisa
NO
divisa
NE
SO
SE

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, x, y, a, b, p, q;
    while (cin >> n)
    {
        if (n==0)
            break;
        cin >> x >> y;
        while (n--)
        {
            cin >> a >> b;
            p = a-x;
            q = b-y;
            if (p==0 || q==0)
                cout << "divisa" << endl;
            else if (p>0 && q>0)
                cout << "NE" << endl;
            else if (p > 0 && q  <  0)
                cout << "SE" << endl;
            else if (p < 0 && q>0)
                cout << "NO" << endl;
            else if (p  <  0 && p < 0)
                cout << "SO" << endl;
        }
    }
    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
3
2 1
10 10
-10 1
0 33
4
-1000 -1000
-1000 -1000
0 0
-2000 -10000
-999 -1001
0

Output

x
+
cmd
NE
divisa
NO
divisa
NE
SO
SE

#2 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("node:fs")
const lines = readFileSync("/dev/stdin", "utf8")
	.split("\n")
	.map((line) => line.split(" ", 2).map(value => Number.parseInt(value, 10)))

const input = (function* (lines) {
	for (const line of lines) yield line
})(lines)

function NlogoniaDelimits(dX, dY) {
	// a palavra divisa se a residência encontra-se em cima de uma das linhas divisórias (norte-sul ou leste-oeste);
	// NO se a residência encontra-se na Nlogônia do Noroeste;
	// NE se a residência encontra-se na Nlogônia do Nordeste;
	// SE se a residência encontra-se na Nlogônia do Sudeste;
	// SO se a residência encontra-se na Nlogônia do Sudoeste.

	return function (x, y) {
		if (x === dX || y == dY) return "divisa"
		if (x > dX && y > dY) return "NE"
		if (x  <  dX && y > dY) return "NO"
		if (x > dX && y < dY) return "SE"
		if (x < dX && y < dY) return "SO"
	}
}

function main() {
	const output = []

	for (let line = input.next(); line.value[0] != 0; line = input.next()) {
		const [delimiters] = line.value
		const [dX, dY] = input.next().value
		const nlogoniaDelimitsInstance = NlogoniaDelimits(dX, dY)

		for (let i = 0; i  <  delimiters; i++) {
			output.push(nlogoniaDelimitsInstance(...(input.next().value)))
		}
	}

	console.log(output.join("\n"))
}

main()
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
2 1
10 10
-10 1
0 33
4
-1000 -1000
-1000 -1000
0 0
-2000 -10000
-999 -1001
0

Output

x
+
cmd
NE
divisa
NO
divisa
NE
SO
SE

#3 Code Example with Python Programming

Code - Python Programming


while True:
    n = int(input())
    if n == 0: break
    x, y = [int(g) for g in str(input()).split()]
    for j in range(n):
        a, b = [int(g) for g in str(input()).split()]
        if a == x or b == y: print('divisa')
        else:
            if x < a:
                if y < b: print('NE')
                else: print('SE')
            else:
                if y < b: print('NO')
                else: print('SO')
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
2 1
10 10
-10 1
0 33
4
-1000 -1000
-1000 -1000
0 0
-2000 -10000
-999 -1001
0

Output

x
+
cmd
NE
divisa
NO
divisa
NE
SO
SE
Advertisements

Demonstration


Previous
#1090 Beecrowd Online Judge Solution 1090 Set Solution in C, C++, Java, Js and Python
Next
#1092 Beecrowd Online Judge Solution 1092 Longest Increasing Sub-sequence Solution in C, C++, Java, Js and Python