UVA 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



题意:一对双胞胎吃一个蛋糕,蛋糕上面有2*n个草莓,为了公平起见,妈妈必须使每个人都能分到n个草莓,蛋糕输一个半径为100的圆。
对于切蛋糕的要求是:(1)必须是一条直线。
                   (2)这条直线必须过圆心(也就是直径),其中圆心在原点                          (0,0)上。
      对于这样的一条直线设的方程为Ax+By = 0,题目已经说明A,B都在[-500,500]这个区间内。求符合条件的A B,并输出。(A,B的值并不唯一,输出一个符合条件的就可以了)



#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

struct node
{
    int x;
    int y;
}q[201];

int n;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        if(n == 0)
        {
            break;
        }
        int m = n;
        n = n* 2;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&q[i].x,&q[i].y);
        }
        int sum1 = 0,sum2 = 0;
        int flag = 0;
        for(int i=-500;i<=500;i++)
        {
            for(int j=-500;j<=500;j++)
            {
                if(i == 0 && j == 0)
                {
                    continue;
                }
                sum1 = 0;
                sum2 = 0;
                for(int k=0;k<2*n;k++)
                {
                    if((i*q[k].x + j*q[k].y) > 0)
                    {
                        sum1++;
                    }
                    else if((i*q[k].x + j*q[k].y) < 0)
                    {
                        sum2++;
                    }
                    else
                    {
                        break;
                    }
                }
                //printf("sum1 = %d      sum2 = %d      m = %d\n",sum1,sum2,m);
                if(sum1 == sum2 && sum1 == m)
                {
                    printf("%d %d\n",i,j);
                    flag = 1;
                    break;
                }
            }
            if(flag == 1)
            {
                break;
            }
        }
    }
    return 0;
}


 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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶孤心丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值