UVa 10167 Birthday Cake:枚举

10167 - Birthday Cake

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_problem&problem=1108

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

本文URL地址:http://www.bianceng.cn/Programming/sjjg/201410/45369.htm

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
枚举A,B即可。

完整代码:

/*0.015s*/

#include <cstdio>
const int maxn = 30;///不需要500那么大,30足矣  

int chx[101], chy[101];  

int main()
{
    int n, cnt, a, b, i;
    bool flag;
    while (scanf("%d", &n), n)
    {
        for (i = 0; i < n * 2; ++i)
            scanf("%d%d", &chx[i], &chy[i]);
        flag = false;
        for (a = -maxn; a <= maxn; ++a)
        {
            for (b = -maxn; b <= maxn; ++b)
            {
                cnt = 0;
                for (i = 0; i < n * 2; ++i)
                {
                    if (chx[i] * a + chy[i] * b == 0)
                    {
                        cnt = 0;
                        break;
                    }
                    else if (chx[i] * a + chy[i] * b > 0) ++cnt;
                }
                if (cnt == n)
                {
                    printf("%d %d\n", a, b);
                    flag = true;
                    break;
                }
            }
            if (flag) break;
        }
    }
    return 0;
}

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索background
is
happy birthday、cube escape birthday、birthday、happy birthday花体字、birthday cake,以便于您获取更多的相关知识。

时间: 2024-10-25 23:35:41

UVa 10167 Birthday Cake:枚举的相关文章

uva 10167 - Birthday Cake

点击打开链接 题目意思:给定一个半径为100的蛋糕,蛋糕上面有许多的樱桃,现在要求一次性平均分蛋糕,并且对应的樱桃的数量要相等.要求这个均分的直线AX+BY = 0的A 和 B的一个解 解题思路:题目规定半径的值,还有A B 的范围,我们知道一条直线能够将点平均分成两半 ,点不会落在直线上,那么我们知道对于点带入直线如果值大于0则点在直线上方,反之在下方. 只要慢足上方的点等于下方的点并且所以点不会落在直线上就可以,三重循环(暴力枚举). 代码: #include <iostream> #in

UVa 140 Bandwidth:枚举全排列&amp;amp;剪枝搜索

140 - Bandwidth Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_problem&problem=76 Given a graph (V,E) where V is a set of nodes and E is a set of arcs in VxV, and anord

UVa 10125 Sumsets (折半枚举&amp;amp;二分查找)

10125 - Sumsets Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1066 Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S

UVa 471 Magic Numbers:枚举

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=412 直接枚举.代码中给出了一个用位运算判断数字中是否有重复数字的方法. 完整代码: 01./*0.032s*/ 02. 03.#include <cstdio> 04.const long long maxn = 9876543210LL; 05.

UVa 1225 Digit Counting:枚举

1225 - Digit Counting Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3666 N<10000,干脆O(NlogN)建表得了. 完整代码: /*0.012s*/ #include<cstdio> int c[10000]

UVa 10360 Rat Attack:枚举和优化

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1301 由于格子数远大于鼠窝,所以以鼠窝为出发点,增加鼠窝周围d范围内的"格子的值",最后扫描每个格子输出最大格子值即可. 完整代码: 01./*0.125s*/ 02. 03.#include<bits/stdc++.h> 04

uva 10730 - Antiarithmetic?

点击打开链接uva 10730 思路:枚举等差中项 分析: 1 给定一个n个数的序列判断是否有等差子序列 2 很明显我们如果要判断是否有等差子序列的话,只要去判断是否有长度为3的等差子序列 3 对于n<=10000,那么我们怎么去判断呢,由于我们要找的是是否有三个的等差序列,那么我们可以枚举每一个数作为等差中项,然后去判断 4 假设现在我们枚举num[i]作为等差中项,那么第一个数在0~i-1之间,第二个数是在i+1~n-1之间,这个时候如果单存利用for循环去找时间复杂度不能接受,那么我们想到

UVa 701 The Archeologists&#039; Dilemma: 数学及枚举

701 - The Archeologists' Dilemma Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=642 An archeologist seeking proof of the presence of extraterrestrials i

UVa 131 The Psychic Poker Player:枚举&amp;amp;模拟好题

131 - The Psychic Poker Player Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_problem&problem=67 In 5-card draw poker, a player is dealt a hand of five cards (which may