Algorithm


problem Link : https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=1806 

Stan and Ollie play the game of Odd Brownie Points. Some brownie points are located in the plane, at integer coordinates. Stan plays first and places a vertical line in the plane. The line must go through a brownie point and may cross many (with the same xcoordinate). Then Ollie places a horizontal line that must cross a brownie point already crossed by the vertical line. Those lines divide the plane into four quadrants. The quadrant containing points with arbitrarily large positive coordinates is the top-right quadrant. The players score according to the number of brownie points in the quadrants. If a brownie point is crossed by a line, it doesn’t count. Stan gets a point for each (uncrossed) brownie point in the top-right and bottom-left quadrants. Ollie gets a point for each (uncrossed) brownie point in the top-left and bottom-right quadrants. Your task is to compute the scores of Stan and Ollie given the point through which they draw their lines. Input Input contains a number of test cases. The data of each test case appear on a sequence of input lines. The first line of each test case contains a positive odd integer 1 < n < 200000 which is the number of brownie points. Each of the following n lines contains two integers, the horizontal (x) and vertical (y) coordinates of a brownie point. No two brownie points occupy the same place. The input ends with a line containing ‘0’ (instead of the n of a test). Output For each test case of input, print a line with two numbers separated by a single space. The first number is Stan’s score, the second is the score of Ollie when their lines cross the point whose coordinates are given at the center of the input sequence of points for this case.

Sample Input 11 3 2 3 3 3 4 3 6 2 -2 1 -3 0 0 -3 -3 -3 -2 -3 -4 3 -7 0

Sample Output 6 3

Code Examples

#1 Code Example with C Programming

Code - C Programming

#include <bits/stdc++.h>
using namespace std;
int fastio() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); cin.tie(nullptr); return 0; }

int __fastio = fastio();

typedef long long ll;
typedef pair < ll, ll> ii;
#define fi first
#define se second
#define sz(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void solve() {
	int n;
	while(cin >> n, n) {
		vector < ii> pts(n);
		for(int i=0;i < n;i++) cin >> pts[i].fi >> pts[i].se;
		auto [mx, my] = pts[n/2];
		int a = 0, b = 0;
		for(auto&[x, y] : pts) {
			if(x == mx || y == my) continue;
			bool left = x < mx;
			bool btm = y  <  my;
			if(left == btm) a++;
			else b++;
		}
		cout << a << " " << b << "\n";
	}
}

int main() {
    int t=1;
    while(t--) {
        solve(>;
    }
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
11
3 2
3 3
3 4
3 6
2 -2
1 -3
0 0
-3 -3
-3 -2
-3 -4
3 -7
0

Output

x
+
cmd
6 3
Advertisements

Demonstration


UVA Online Judge solution - 10865-Brownie Points - UVA Online Judge solution in C,C++,java

Previous
UVA Online Judge solution10843 - 10858-Unique Factorization - UVA Online Judge solution in C,C++,java
Next
UVA Online Judge solution - 10878-Decode the tape - UVA Online Judge solution in C,C++,java