UVa10167 Birthday Cake


 Problem G. Birthday Cake 

Background

Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them.Now we put the cake onto a Descartes coordinate. Its center is at (0,0), and the cake's length of radius is 100.

There are 2N (N is a integer, 1<=N<=50) cherries on the cake. Mother wants to cut the cake into two halves with a knife (of course a beeline). The twins would like to be treated fairly, that means, the shape of the two halves must be the same (that means the beeline must go through the center of the cake) , and each half must have N cherrie(s). Can you help her?

Note: the coordinate of a cherry (x , y) are two integers. You must give the line as form two integers A,B(stands for Ax+By=0), each number in the range [-500,500]. Cherries are not allowed lying on the beeline. For each dataset there is at least one solution.

Input

The input file contains several scenarios. Each of them consists of 2 parts:The first part consists of a line with a number N, the second part consists of 2N lines, each line has two number, meaning (x,y) .There is only one space between two border numbers.The input file is ended with N=0.

Output

For each scenario, print a line containing two numbers A and B. There should be a space between them. If there are many solutions, you can only print one of them.

Sample Input

2
-20 20
-30 20
-10 -50
10 -5
0

Sample Output

0 1


这道题大意是有一个蛋糕,上面有许多的蜡烛,然后要求在圆心切一刀,把蛋糕分成两块,且两边蜡烛数量相同。我是利用了暴力搜索,直接搜索x,y坐标在[-500,500]内的节点,算出这条线段的方程,然后与各个蜡烛的坐标进行比较是否满足两端蜡烛数目相同。然后输出x,y。

#include<iostream>
#include<cstring>
using namespace std;

const int INF = 1<<29;
const int MAX = 500;
const int R = 100;
const int C = 50;
int N;
struct cherries{
	int x;
	int y;
}c[2*C];

struct slope{
	double k;
	int num;
}s[2*MAX][2*MAX];

void ini(){
	memset(c,0,sizeof(c));
	memset(s,0,sizeof(s));
}

bool find(int i,int j){
	for (int p = 0; p <= 2*MAX; p++){
		for (int q = 0; q <= 2*MAX; q++){
			if (s[p][q].sign && s[p][q].k == s[i][j].k){
				return true;
			}
		}
	}
	return false;
}

bool cut(int a,int b){
	for (int i = 0; i < 2*N; i++){
		if ((a-MAX)*c[i].x+(b-MAX)*c[i].y > 0)
			s[a][b].num++;
		else if ((a-MAX)*c[i].x+(b-MAX)*c[i].y < 0)
			s[a][b].num--;
		else if ((a-MAX)*c[i].x+(b-MAX)*c[i].y == 0)
			return false;
	}
	if (!s[a][b].num){
		cout << a-MAX << " " << b-MAX << endl;
		return true;
	}
	else
		return false;
}

int main(){
	while (cin >> N){
		if (N == 0)
			break;
		ini();
		for (int i = 0; i < 2*N; i++){
			cin >> c[i].x;
			cin >> c[i].y;
		}
		bool tmp = false;
		for (int i = 0; i <= 2*MAX; i++){
			for (int j = 0; j <= 2*MAX; j++){
				if (cut(i,j)){
					tmp = true;
					break;
				}
			}
			if (tmp)
				break;
		}
	}
	return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值