UVA 10167 Birthday Cake

来源:互联网 发布:乳胶漆配色软件. 编辑:程序博客网 时间:2024/06/17 17:51

分析

对于一条直线Ax+By=0,如果一点(a,b)满足Aa+Bb>0则该点位于该直线上方,满足Aa+Bb<0则该点位于该直线下方,满足Aa+Bb=0则该点位于该直线上。
直接枚举所有可能的AB,只要上方和下方的个数均等于N,枚举结束。

思路

因为如果存在一颗樱桃在这个切割线上,那么一定不能如此切割,所以如果存在一点在该线上,那么可以跳过这组(A,B),适当剪枝。

代码

#include <cstdio>#define MAX_N 52int cherries[MAX_N<<1][2];int N;void solve(){    for (int A = -100; A <= 100; A++)        for (int B = -100; B <= 100; B++) {            int u = 0, d = 0;            for (int i = 0; i < (N<<1); i++)                if      (A*cherries[i][0] + B*cherries[i][1] > 0) u++;                else if (A*cherries[i][0] + B*cherries[i][1] < 0) d++;                else break;            if (u == N && d == N) {                printf("%d %d\n", A, B);                return;            }        }}int main(){    while (scanf("%d", &N), N) {        for (int i = 0; i < (N<<1); i++)            scanf("%d%d", &cherries[i][0], &cherries[i][1]);        solve();    }    return 0;}

题目

Description

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 2 N (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 mustn’t in [−500, 500]. Cherries are not allowed lying on the beeline. For each data set 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 2 N 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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 橡皮树长得太高怎么办 金钻的叶子下垂怎么办 水养竹子烂根怎么办 散尾竹叶尖干枯怎么办 眼睛看不清东西视线模糊怎么办 棒球服领子松垮怎么办 裱水彩纸崩了怎么办 裱水彩纸皱起来怎么办 冬天皮肤的皴了怎么办 六个月宝宝皴脸怎么办 婴儿冬天脸裂了怎么办 手裂了怎么办 小妙招 幼儿园孩子不爱写作业怎么办 2岁宝淘气不听话怎么办 2岁宝宝太调皮怎么办 ae视频加载的慢怎么办 我想你了怎么办表情包 腰闪了不能弯腰怎么办 13岁驼背怎么办才能好 脸僵硬笑不出来怎么办 素描排线太乱了怎么办 4岁小儿不爱吃饭怎么办 僵尸农场下架了怎么办 乐视倒闭了手机怎么办 小孩笑起来嘴歪怎么办 小孩嘴歪了怎么办啊 头发长洗头掉发怎么办 头痒又掉头发怎么办 头皮痒而且掉发怎么办 掉一片头发头痒怎么办 头头发掉的厉害怎么办 掉发严重怎么办吃什么 18岁脱发严重该怎么办 高三学生掉头发怎么办 20岁一直掉头发怎么办 孩子掉头发很厉害怎么办 6岁掉头发正常怎么办 掉头发严重怎么办知乎 20岁有白头发怎么办 20岁掉头发很厉害怎么办 20岁每天掉头发怎么办