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

 

随机:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
const int N=100;
int x[N];
int y[N]; int n; void solve()
{
while(1)
{
int A,B;
A=rand()%1001-500;
B=rand()%1001-500; int small=0;
int big=0;
for(int i=0;i<2*n;i++)
{
int v=A*x[i]+B*y[i];
if(v>0)
big++;
else if(v<0)
small++;
else
break;
}
//printf("%d %d\n", small, big);
if(small==n && big==n)
{
cout<<A<<" "<<B<<endl;
return;
} }
} int main()
{
srand(time(0));
while(cin>>n&&n)
{
for(int i=0;i<2*n;i++)
{
cin>>x[i]>>y[i];
}
solve();
} return 0;
}

 

暴力:

void solve()
{
for(int A=-500;A<=500;A++)
{
for(int B=-500;B<=500;B++)
{
int small=0;
int big=0;
for(int i=0;i<2*n;i++)
{
int v=A*x[i]+B*y[i];
if(v>0)
big++;
else if(v<0)
small++;
else
break;
}
//printf("%d %d\n", small, big);
if(small==n && big==n)
{
cout<<A<<" "<<B<<endl;
return;
}
}
}
}

Uva 10167 - Birthday Cake 暴力枚举 随机的更多相关文章

  1. UVA.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

  2. UVA - 10167 - Birthday Cake (简单枚举)

    思路:简单枚举 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include &l ...

  3. Brute Force --- UVA 10167: Birthday Cake

     Problem G. Birthday Cake  Problem's Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudg ...

  4. uva 10167 - Birthday Cake

    题解:由于解太多,随机抓 A.B, 只要有符合就行了: (首先,Ax+By=0必须表示直线,即A.B不能同时为0:另外,要注意到直线不能过输入中的2N个点:检测点在直线的哪一侧,只需要简单的线性规划的 ...

  5. UVA 725 division【暴力枚举】

    [题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...

  6. UVa 10603 Fill [暴力枚举、路径搜索]

    10603 Fill There are three jugs with a volume of a, b and c liters. (a, b, and c are positive intege ...

  7. UVA 10012 How Big Is It?(暴力枚举)

      How Big Is It?  Ian's going to California, and he has to pack his things, including his collection ...

  8. uva 11088 暴力枚举子集/状压dp

    https://vjudge.net/problem/UVA-11088 对于每一种子集的情况暴力枚举最后一个三人小组取最大的一种情况即可,我提前把三个人的子集情况给筛出来了. 即 f[S]=MAX{ ...

  9. UVA - 11464 Even Parity 【暴力枚举】

    题意 给出一个 01 二维方阵 可以将里面的 0 改成1 但是 不能够 将 1 改成 0 然后这个方阵 会对应另外一个 方阵 另外一个方阵当中的元素 为 上 下 左 右 四个元素(如果存在)的和 要求 ...

随机推荐

  1. 树莓派 安装 php

    执行如下命令(注意红色字部分是关键!) sudo apt-get install apache2 php5 libapache2-mod-php5 然后把网页文件复制到 /usr/www 中即可 参考 ...

  2. Team Foundation Server 2010下载安装配置方法

    一.Team Foundation Server 2010下载: ed2k://|file|cn_visual_studio_team_foundation_server_2010_x86_x64_d ...

  3. Eclipse for PHP Developers + xamp +xdebug

    php 开发环境搭建 1.安装xamp 我的版本是v3.2.1 2.安装下载“Eclipse for PHP Developers”解压即可使用 3.配置“Eclipse for PHP Develo ...

  4. 嵌入式 H264中的SPS、PPS提取与作用

    使用RTP传输H264的时候,需要用到sdp协议描述,其中有两项:Sequence Parameter Sets (SPS) 和Picture Parameter Set (PPS)需要用到,那么这两 ...

  5. cefSharp在XP下使得程序崩溃记录

    前言:这是一个奇葩的问题,到现在自己还没有搞明白问题出现在哪里,但是从问题总算是解决了,希望看到此文章的大牛,如果知道问题出在什么地方,可以告知一下. [一个在XP系统下面应用程序崩溃问题] 资源: ...

  6. 【转】SQL Server 数据库内部版本号

    -----------数据库还原或版本升级出现版本错误时可参考. Internal SQL Server Database Version Numbers A database created by ...

  7. 前端技能汇总 Frontend Knowledge Structure

    Frontend Knowledge Structure 项目起源 还记得@jayli 的这幅前端知识结构图么. 图片的形式具有诸多的不便.缺失源图的我们,无法为此图贡献些什么,随着时间的迁移,或许有 ...

  8. 为网页设计师准备的30个使用的HTML5框架

    原文地址:http://www.goodfav.com/zh/html5-framework-8189.html 网页设计师在开始使用一些应用程序之前需要考虑几个事实,以确保在应用Web程序框架时,这 ...

  9. erlang 常用函数

    os:getpid() 获得erl.exe的进程表示符 application:start(appname,    Type), Type == permanent 表示一个应用死了,其它应用全部死掉 ...

  10. LINQ标准查询操作符(一)——select、SelectMany、Where、OrderBy、OrderByDescending、ThenBy、ThenByDescending和Reverse

    一.投影操作符 1. Select Select操作符对单个序列或集合中的值进行投影.下面的示例中使用select从序列中返回Employee表的所有列: //查询语法 var query = fro ...