ZOJ Problem Set - 2554 Brownie Points

Brownie Points

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 x-coordinate). 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

Source: University of Waterloo Local Contest 2005.06.11

解题思路:

本题主要是将输入的中间数n/2当成原点,Stan 的成绩在第一和第三象限的点 Ollie的成绩在第二和第四象限的点。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
	int x,y;
};
int main()
{
	int n;
	while(scanf("%d",&n)&&n)
	{
		int ans,op;
		ans=op=0;
		node *p=new node[n];
		int i,j;
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&p[i].x,&p[i].y);
		}	
		int xx,yy;
		xx=p[n/2].x;
		yy=p[n/2].y;
		for(i=0;i<n;i++)
		{
			if((p[i].x>xx&&p[i].y>yy)||(p[i].x<xx&&p[i].y<yy))
			{
				ans++;
			}
			else if((p[i].x>xx&&p[i].y<yy)||(p[i].x<xx&&p[i].y>yy))
			{
				op++;
			}
		}
		printf("%d %d\n",ans,op);
	}
	return 0;
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值