UVA 10167 - 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

 

总结问题:
1 产生a,b 用两个for,没用随机数,导致WA
2 没有用while 和n=0的判断,WA
3 数组开的太小了,WA
 
 
#define RUN
#ifdef RUN

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <cctype> 
#include <algorithm>
#include <utility>
#include <math.h>
#include <ctime>

using namespace std;

#define MAXN 110

int input[MAXN][2];
int n;

void printout(){
	cout << "2*n:" << 2*n << endl;
	for(int i=0; i<2*n; i++){
		printf("%d %d\n", input[i][0], input[i][1]);
	}
}


void play(){
	
	int pos=0, neg=0;

	while(true){
		int a = -500 + (rand()%1001);
		int b = -500 + (rand()%1001);

		pos = 0;
		neg = 0;
		for(int k=0; k<2*n; k++){
			int sign = a*input[k][0] + b*input[k][1];
			if(sign > 0){
				pos++;
			}
			else if(sign < 0){
				neg++;
			}

			if(pos>=n && neg>=n){
				printf("%d %d\n", a, b);
				return;
			}
		}
	}
}


int main(){

#ifndef ONLINE_JUDGE
	freopen("10167.in", "r", stdin);
	freopen("10167.out", "w", stdout);
#endif

	srand ( time(NULL) );
	while(scanf("%d",&n)==1 && n!=0){
		memset(input, 0, sizeof(input));
		for(int i=0; i<2*n; i++){
			scanf("%d%d", &input[i][0], &input[i][1]);
		}
		play();
		//printout();
	}
	
	return 0;
}


#endif


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值