uva 10167 - Birthday Cake

点击打开链接

题目意思:给定一个半径为100的蛋糕,蛋糕上面有许多的樱桃,现在要求一次性平均分蛋糕,并且对应的樱桃的数量要相等。要求这个均分的直线AX+BY = 0的A 和 B的一个解

解题思路:题目规定半径的值,还有A B 的范围,我们知道一条直线能够将点平均分成两半 ,点不会落在直线上,那么我们知道对于点带入直线如果值大于0则点在直线上方,反之在下方。

只要慢足上方的点等于下方的点并且所以点不会落在直线上就可以,三重循环(暴力枚举)。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

struct Point{
    int x;
    int y;
};
Point p[110];
int n , cnt1 , cnt2;

void solve(){
    int i , j;
    for(i = -500 ; i <= 500 ; i++){
        for(j = -500 ; j <= 500 ; j++){
            cnt1 = 0; cnt2 = 0;
            for(int k = 0 ; k < 2*n ; k++){
                if((i*p[k].x + j*p[k].y) < 0)
                    cnt1++;
                if((i*p[k].x + j*p[k].y) > 0)
                    cnt2++;
            }
            if(cnt1  == cnt2){
                printf("%d %d\n" , i , j);
                return;
            }
        }
    }
}

int main(){
   int i;
   while(scanf("%d" , &n) &&n){
       for(i = 0 ; i < 2*n ; i++)
           scanf("%d %d" , &p[i].x , &p[i].y);
       solve();
   }
   return 0;
}
时间: 2024-09-11 13:05:07

uva 10167 - Birthday Cake的相关文章

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 bir

UVa 10602

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1543 类型:贪心 原题: Company Macrohard has released it's new version of editor Nottoobad, which can understand a few voice commands.

UVa 10392 Factoring Large Numbers:素因子分解

10392 - Factoring Large Numbers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=1333 One of the central ideas behind much cryptography is that factoring

UVa 10182 Bee Maja:规律&amp;amp;O(1)算法

10182 - Bee Maja Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1123 Maja is a bee. She lives in a bee hive with thousands of other bees. This bee hive c

算法题之UVA 763

Fibinary Numbers The standard interpretation of the binary number 1010 is 8 + 2 = 10. An alternate way to view the sequence ``1010'' is to use Fibonacci numbers as bases instead of powers of two. For this problem, the terms of the Fibonacci sequence

算法题:UVa 11461 Square Numbers (简单数学)

11461 - Square Numbers Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=24 56 A square number is an integer number whose square root is also an integer.

UVa 10183 How Many Fibs? (统计斐波那契数个数&amp;amp;高精度)

10183 - How Many Fibs? Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1124 Recall the definition of the Fibonacci numbers:    f1 := 1    f2 := 2    fn :

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 550 Multiplying by Rotation:模拟乘法

550 - Multiplying by Rotation Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=491 Warning: Not all numbers in this problem are decimal numbers! Multiplic