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. MySQL与Oracle 差异比较之六触发器

    触发器 编号 类别 ORACLE MYSQL 注释 1 创建触发器语句不同 create or replace trigger TG_ES_FAC_UNIT  before insert or upd ...

  2. 关于RF 315MHz

    1.https://www.pjrc.com/teensy/td_libs_VirtualWire.html These modules worked very reliably when sitti ...

  3. T-SQL:SQL Server-数据开发(经典)

    ylbtech-SQL Server-Doc-Help:SQL Server-数据开发(经典) SQL Server 数据开发(经典). 1,数据开发(经典) 返回顶部 1.按姓氏笔画排序: Sele ...

  4. LR之配置端口映射(port mapping)

    1.那些协议需要配置 tools-recording_options-network-port mapping 2.定义端口映射 3.自动检测原理 4.特殊情况

  5. linux grub

    grub 是目前使用最广泛的linux引导装载程序,旧的lilo这个引导装载程序很少见了,grub优点: 支持较多哦的文件系统,可以使用grub主程序在文件系统中查找内核文件名 启动的时候,可以自行编 ...

  6. 【JNI】OPUS压缩与解压的JNI调用(.DLL版本)

    OPUS压缩与解压的JNI调用(.DLL版本) 一.写在开头: 理论上讲,这是我在博客园的第一篇原创的博客,之前也一直想找个地方写点东西,把最近做的一些东西归纳总结下,但是一般工程做完了一高兴就把东西 ...

  7. java-web查询系统

    1:select标签.选择列表~ 让从数据库得到的科目名称全部放入一个ArrayList里,用for循环将其遍历.数据库存取暂不介绍. 效果图: classC班没有此分数段,所以我改成classA p ...

  8. CentOS6.5修改mysql数据文件路径

    1.停止mysql服务      service mysql stop 2.移动数据文件位置(保留原文件权限)      cp -a /var/lib/mysql /mysqldata 3.修改/et ...

  9. java 编写hadoop程序中使用第三方libxx.so库

    在使用java编写hadoop处理程序时遇到了,java使用依赖的第三方libxx.so库的情况,找到了一种可行的方法,记录一下,希望对别人也有帮助: 加入需要使用的lib库为libxxx.so 1. ...

  10. 【转】类中如何引用server.MapPath()

    转至:http://blog.csdn.net/tangjianft/article/details/5357151 今天在写一个上传图片方法时遇到了两个问题:1.public string getI ...